好心人帮忙看看怎么改,先谢了
文本格式如下
【题名】asdfasdf
【中译题名】asdfdsaf
【原文作者】Farid Rsdf
【摘要】zfadeefs
【全文】zfadeefs
现代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
System.IO.StreamReader sr = new System.IO.StreamReader( "c:/2.txt ");
while ((input = sr.ReadLine()) != null)
{
insertSql( "c:/2.txt ");
}
sr.Close();
}
private void insertSql(string str)
{
SqlConnection conn = new SqlConnection( "server=192.168.1.168;uid=sa;pwd=123;database=0707 ");
SqlCommand cmd = new SqlCommand( "insert into test2005 values ( ' " + str + " ') ", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
}
------解决方案--------------------------------------------------------
要你就截取所读出来的字符串好了,如果格式都一样的话
System.IO.StreamReader sr = new System.IO.StreamReader( "c:/2.txt ");
string str = string.Empty;
while ((str = sr.ReadLine()) != null)
{
str = str.Substring(str.IndexOf( "] ")+1).Trim();
insertSql(str);
}
sr.Close();