|
-
October 16th, 2008, 03:50 PM
#1
ado.net
SqlConnection myconnection = new SqlConnection("server=RHGVR-1667F3F5E;Database=vanamu;Trusted_Connection=yes;");
myconnection.Open();
SqlCommand mycommand = new SqlCommand("insert Usedetails ( Personname, Address, City, State, Zip) values( Rami, lutz hall, commerce, texas, 75429)");
mycommand.ExecuteNonQuery();
myconnection.Close()
In the above code plz correct the store procedure that i have used there. and also the connection strings. Iam getting errors.
-
October 16th, 2008, 04:25 PM
#2
Re: ado.net
Several things:
- It's best to provide the actual text of the errors you're getting. Your code may be correct but the environment may have issues. The actual error messages help decipher that.
- Please make sure to use code tags around your code, it makes things much more readable.
- You're not using a stored procedure, that's an ad hoc query. You need to add ' marks around each of your string values.
- For your connection issues, refer to www.connectionstrings.com for examples of connecting to assorted databases.
-
October 18th, 2008, 03:08 AM
#3
Re: ado.net
No you code is not Correct , mmetzger is right, Show us the Whole code, but now your Conection string is incorrect.
Your Connection string should look like this, Change it from
Code:
SqlConnection myconnection = new SqlConnection("server=RHGVR-1667F3F5E;Database=vanamu;Trusted_Connection=yes;");
to this
Code:
SqlConnection myconnection = new SqlConnection("User ID=sa;Password=hello; Server=RHGVR-1667F3F5E;Database=vanamu;Trusted_Connection=yes");
Another thing i saw is that you open the connection in a wrong place. You must open the connection when you are about to execute something. That means the code that you just posted to us should look like this .
Code:
SqlConnection myconnection = new SqlConnection("User ID=sa;Password=hello; Server=RHGVR-1667F3F5E;Database=vanamu;Trusted_Connection=yes");
SqlCommand mycommand = new SqlCommand("insert Usedetails ( Personname, Address, City, State, Zip) values( Rami, lutz hall, commerce, texas, 75429)");
try
{
myconnection.Open();
mycommand.ExecuteNonQuery();
}
catch(SQlexception)
{
Finnaly
{
myconnection.Close();
}
}.....
, i did not do this in Vs , I hope you see the idea. Do not write untidy code , because it might Confuse you too
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|