本文介绍了在c#中插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是我插入数据库的代码....但它会停止并在connection.Open();中显示运行时错误CmdSql.ExecuteNonQuery();



需要你的帮助才能继续前进



Hi

this is my code for insert to database .... but it will stop and show a run time error in connection.Open();and CmdSql.ExecuteNonQuery();

NEED ur help to move forward here on

SqlConnection connection = new SqlConnection();
           connection.ConnectionString = "Data Source=ASA-PC\\SQLEXPRESS; Initial Catalog=Material_database; User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=10";
           connection.Open();

           {
               SqlCommand CmdSql = new SqlCommand("INSERT INTO [mat_utiAndtrans](Project, Date, Team_Leader, Vendor, WO, Rate,Code,Qty,Officer,Remark) VALUES (@Project, @Date, @Team_Leader, @Vendor, @WO, @Rate,@Code,@Qty,@Officer,@Remark)", connection);
               connection.Open();
               CmdSql.Parameters.AddWithValue("@Project", txtproject.Text);
               CmdSql.Parameters.AddWithValue("@Date", txtdte.Text);
               CmdSql.Parameters.AddWithValue("@Team_Leader", txtTeamleader.Text);
               CmdSql.Parameters.AddWithValue("@Vendor", txtvendor.Text);
               CmdSql.Parameters.AddWithValue("@WO", txtwo.Text);
               CmdSql.Parameters.AddWithValue("@Rate", txtrate.Text);
               CmdSql.ExecuteNonQuery();
               connection.Close();

推荐答案



这篇关于在c#中插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:14