从Text文本中读值插入到数据库中
/// <summary>
??/// 轉(zhuǎn)換數(shù)據(jù),從Text文本中導(dǎo)入到數(shù)據(jù)庫(kù)中
??/// </summary>
??private void ChangeTextToDb()
??{
???if(File.Exists("Storage Card/Zyk.txt"))
???{
????try
????{
?????this.RecNum.Visible=true;
?????SqlCeCommand sqlCreateTable = Mc.gConn.CreateCommand();??
?????StreamReader reader = new StreamReader("Storage Card/Zyk.txt", System.Text.Encoding.Default);
?????int i=0;
?????while (reader.Peek() > 0)
?????{
????
??????string oneLine = reader.ReadLine();
??????string ztm = this.MySubstring(oneLine,0,100).Trim().Replace("'","’");
??????string date = this.MySubstring(oneLine,100,8).Trim().Replace("'","’");
??????string isbn = this.MySubstring(oneLine,108,20).Trim().Replace("'","’");
??????string fbs? = this.MySubstring(oneLine,128,10).Trim().Replace("'","’");
??????if(fbs=="0"||fbs==null||fbs==""||isbn==""||isbn==null)
??????{??????
??????}
??????else
??????{
??????
???????isbn=NcIsbn.Format(isbn,13).Replace("-","");
???????sqlCreateTable.CommandText = "insert into ZYK(Title,RDate,ISBN,BookNum) values('"+ztm +"','"+date+"','"+isbn+"',"+ fbs+")";
???????sqlCreateTable.ExecuteNonQuery();
???????i+=1;
???????if(i%100==0)
???????{
????????this.RecNum.Text=i.ToString();
????????this.RecNum.Refresh();
???????}
??????}
??????
?????}
?????reader.Close();
?????MessageBox.Show("館藏?cái)?shù)據(jù)成功導(dǎo)入"+i.ToString().Trim()+"條!");
?????this.RecNum.Visible=false;
????}
????catch
????{
?????MessageBox.Show("館藏?cái)?shù)據(jù)導(dǎo)入失敗請(qǐng)檢查格式!");
?????this.RecNum.Visible=false;
????}
???}
???else
???{
????MessageBox.Show("沒(méi)有Zyk.txt文件!");
???}
??
???
??}?
總結(jié)
以上是生活随笔為你收集整理的从Text文本中读值插入到数据库中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 文本二叉树折半查询及其截取值
- 下一篇: 从数据库里读值往TEXT文本里写