Insertion Problem into Database
-
hi everyone. i am inserting values in the table the code.
SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close();
This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance. -
hi everyone. i am inserting values in the table the code.
SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close();
This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance.Reconfirm if the connectionstring is perfect. I think it is inserting in some other database ... If ADO.NET cannot insert in database, it will throw you an error. ;P
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NET -
Reconfirm if the connectionstring is perfect. I think it is inserting in some other database ... If ADO.NET cannot insert in database, it will throw you an error. ;P
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NETsir thank you for your reply i have checked the connectionstring it is ok. and i have no other database with same name and table, columns only the select query work. nor update and nor delete and nor insert work.
-
sir thank you for your reply i have checked the connectionstring it is ok. and i have no other database with same name and table, columns only the select query work. nor update and nor delete and nor insert work.
Try inserting the data inside the transaction and commit the transaction in .net code
modified on Wednesday, December 30, 2009 12:48 PM
-
hi everyone. i am inserting values in the table the code.
SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close();
This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance.Put a breakpoint in the
con.Open()
line and check the connection string property of connection object. Sometimes the connection string itself referring a wrong location. As the other user said, ADO.NET will throw error if the execute fails. So, you must me referring a wrong database.Zafar Ali Khan 1900 wrote:
com.CommandText="insert into <DATABASENAME>.dbo.tbl([Name],FName,Address) values('Angelina','Carlos','sedny')";
replace the <DATABASENAME> with your database name (Full qualifier name). This would help if two or more databases has table in same name and your connection string does not have any Initial Catalog mentioned (default is master database). Better you post your connection string also
Castle Rider
What if I freeze??? Don't forget to breath...
My: Website | Yahoo Group | Blog Spot