if u really tried u can find that code anywhere on the net
u r a beginner, so, just this one time i will give the code ::
Code:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\trial.mdf;Integrated Security=True;User Instance=True"); //change the connection string accordingly
SqlCommand sqlCmd = new SqlCommand(string.Format("INSERT INTO [sum] VALUES ({0}, '{1}')", TextBox1.Text, TextBox2.Text), sqlConnection);//first is int type and second varchar type
try{
sqlConnection.Open();
int rowsAffected = sqlCmd.ExecuteNonQuery();
sqlConnection.Close();
Label1.Text = rowsAffected.ToString() + " record(s) inserted sucessfully";
}
catch(Exception ex)
{
Label1.Text = "Error: " + ex.Message;
}
finally{
sqlConnection.Close();
}
}
include namespace
Code:
using System.Data.SqlClient;
and put a label with id Label1
i suppose the code is fairly easy to understand. if in doubt break up the code and try to find it on the net
i recommend a great site. used it in my early days ::
http://csharp.net-informations.com/