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());
}
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();
}

hey hi dickersonka

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

Add the code to what a form?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.