日期:2014-05-20  浏览次数:20816 次

为什么C#.net的Windows应用程序操作SQL Server2005会出现提示数据插入成功而并没有把数据插入到数据库中 ,为什么呢?
http://blog.163.com/ysli_195/blog/static/42054194200772925424164/
这页面有咋说,但我不怎么砍得懂,还有我用的是linq to sql;都不知道怎么改了···




找了很多贴,都没有解决方法~~
这是插入操作:
   /// <summary>
   /// 借书函数
   /// </summary>
   /// <param name="o"></param>
   /// <returns></returns>
   public bool insertbook(StuBook o)//借书
   {
     
   try
   {   
     
   db.StuBook.InsertOnSubmit (o);
   db.SubmitChanges();
     
   return true;
   }
   catch (SystemException )
   { return false; }

   }
这是windows窗体调用这个函数:
   private void btborrow_Click(object sender, EventArgs e)
   {
   loginuser user = new loginuser();
   book boook = new book();
   Stdmessge stu = new Stdmessge();
   if (tbname.Text == "" || tbauthor.Text == "")
   MessageBox.Show("书名和作者不能为空!", "提示", MessageBoxButtons.OKCancel , MessageBoxIcon.Exclamation);
   else {
   if (tbpsw.Text == "")  
   MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
   else {
   stu=user.searchstu(tbid.Text.Trim (), tbpsw.Text.Trim());//确定是否存在该用户
   if (stu != null)
   {
   if( (MessageBox.Show("确定要借书?", "提示", MessageBoxButtons.OKCancel) )== DialogResult.OK)
   {
   StuBook stb = new StuBook();
   stb.BbolowDate = DateTime.Now.Date ;//借书时间
   stb.BreturnDate = DateTime.Now.AddMonths(1);//归还时间
   stb.SBname = tbname.Text.Trim();//书名
   stb.SBauthor = tbauthor.Text.Trim();//作者
   stb.SID = tbid.Text.Trim();//卡号
   if (user.insertbook (stb))//插入
   { if (MessageBox.Show("已借图书:" + tbname.Text + "\n待归还日期:" + DateTime.Now.AddMonths(1).ToShortDateString () + "\n借书成功", "提示", MessageBoxButtons.OK) == DialogResult.OK) { tbauthor.Text = ""; tbname.Text = ""; } }
   else MessageBox.Show("借书失败", "提示", MessageBoxButtons.OK);

   }
   }   
     
   }
  
     
   }
   }
数据不能插入到数据库中,这是为什么呢?但操作显示成功,这真怪了~纠结了好久了,已经尝试过断点调式了···但是···
------解决方案--------------------
又发了一帖,看来还没研究出来啊
------解决方案--------------------
现在解决了····呵呵,http://blog.163.com/ysli_195/blog/static/42054194200772925424164/ 这个很有帮助,当时我找不到linq 数据库的连接字符是放在哪个文件·是放在app.config那个文件··幸好叫同学帮忙···哎···