0

Hello everyone

I have a problem with the connection of MS sql with the windows application problem.

All i need to do is to insert something to the database table. However i'm not sure how to connect the ms sql with it.
I have some codes written out, but i not sure if is placed in the correct order...
Please advise and help if u know how to do it correctly.
Million thanks to anyone who is kind enough to reply my post.

string sCxn = "server=myServer;Integrated Security=SSPI; database=master";
SqlConnection myConnection = new SqlConnection(sCxn );

try
{
    myConnection.Open();  
SqlCommand  myCommand.Connection = myConnection;


    myCommand.CommandText = "INSERT ....";
myCommand.ExecuteNonQuery();
}
catch(Exception e)
{
    Console.WriteLine(e.ToString());
}
2
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by dickersonka
0
string sCxn = "server=myServer;Integrated Security=SSPI; database=master";
string insertQuery = "INSERT ....";
SqlConnection myConnection = new SqlConnection(sCxn);

try
{    
SqlCommand  myCommand = new SqlCommand(insertQuery, myConnection);
myConnection.Open();  
myCommand.ExecuteNonQuery();
}
catch(Exception e)
{
    Console.WriteLine(e.ToString());
}
finally
{
  myConnection.Close();
}
0

hey hi dickersonka

Just to confirm, where do i add the codes to?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.