Click here to Skip to main content
15,561,817 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello all.
I'm using C#.NET(2013) and SQL Server(2014).
What's this code's error?
C#
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");

Error:
Cannot insert the value NULL into column 'bookISBN', table 'myDB.dbo.Book'; column does not allow nulls. INSERT fails.
Posted
Comments
Herman<T>.Instance 13-Jan-16 5:05am    
dt.Rows.Add(dt); --> dt.Rows.Add(dr); !!

1 solution

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


add
data row here
C#
dt.Rows.Add(dr);
 
Share this answer
 
Comments
Pouria Polouk 13-Jan-16 5:11am    
thanks.
that's right.
I was mistaken.
Dj@y 13-Jan-16 5:17am    
it's all right! best luck!
Pouria Polouk 13-Jan-16 5:20am    
thank you so much dear friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900