你看一下我这种写法,应该可以插入数据。。- string strCon = "server=.;database=MySchool;uid=sa;pwd=huangqun" ;//连接服务器
- string sql = "insert into Person(Id,Name,Age) values(4,'小华',19)" ;//sql插入语句
- using ( SqlConnection con = new SqlConnection (strCon))
- {
- con.Open();
- SqlCommand com = new SqlCommand(sql, con); //对数据源执行命令
- try
- {
- int result = com.ExecuteNonQuery();
- if (result>0)
- {
- Console.WriteLine( "数据插入成功!" );
- }
- }
- catch ( Exception ec)
- {
- Console.WriteLine(ec.Message);
- }
- }
复制代码 |