使用C#向表添加行的问题 [英] Problem with adding row to table using C#

查看:60
本文介绍了使用C#向表添加行的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我正在使用C#.NET(2013)和SQL Server(2014)。

这段代码的错误是什么?

hello all.
I'm using C#.NET(2013) and SQL Server(2014).
What's this code's error?

SqlConnection conn = new SqlConnection("database=myDB;data source=(local); integrated security=true");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Book", conn);
DataSet ds = new DataSet();
da.Fill(ds, "Book");
DataTable dt = ds.Tables["Book"];

DataRow dr = dt.NewRow();

dr["bookName"] = "C#.NET";
dr["bookISBN"] = "FW-593"; //Primary Key
dr["bookPrice"] = "15000";
dr["bookPubDate"] = "1392/1/9";

dt.Rows.Add(dt);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds,"book");



错误:

无法将值NULL插入列'bookISBN',表'myDB.dbo.Book';列不允许空值。 INSERT失败。


Error:
Cannot insert the value NULL into column 'bookISBN', table 'myDB.dbo.Book'; column does not allow nulls. INSERT fails.

推荐答案

请检查

此行

please check
this line
dt.Rows.Add(dt);





add

数据行



add
data row here

dt.Rows.Add(dr);


这篇关于使用C#向表添加行的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆