Sunday, February 19, 2012

c# And SQL Server. Why "select" can transac but "insert" ?

string connectionString;
string queryString;
SqlConnection sqlconnection;connectionString="server=fatyi;integrated security=SSPI;initial catalog=tempdb";
queryString="insert into products values(5,'BaoMa',200596,900000,0)";
sqlconnection=new SqlConnection(connectionString);
SqlCommand addScorce=new SqlCommand(queryString,sqlconnection);
sqlconnection.Open();
addScorce.ExecuteNonQuery();
sqlconnection.Close();

help to find out why? if i use "select" it can transaction in this code. And here "insert" .My WebAplication could work,but have no result of "insert".and no error information.The "insert" purview of "products" table have selected.
I help you can help me to point out maybe where is error.
Thank you !Did you try using a Try...Catch block?

And also, are there 5 columns in your table? You might consider specifying your column names in your INSERT statement, like:
INSERT INTO products (column1, column2, column3, column4, column5) values(5,'BaoMa',200596,900000,0)

Terri

No comments:

Post a Comment