hi prerak,
thanks to other soloutions,
i think that it will be helpful.
first of all you should do this:
using system.data.sqlclient();
This code is for insert to table :
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conection = new SqlConnection("Data Source=.;Initial Catalog=YOUR DATABASE NAME;Integrated Security=True;");
string Sql_Insert=("INSERT INTO YOUR TABLE NAME VALUES(@id, @fname, @lname)");
conection.Open();
try
{
SqlCommand comand = new SqlCommand(Sql_Insert, conection);
comand.Parameters.AddWithValue("@id", textBox1.Text);
comand.Parameters.AddWithValue("@fname", textBox2.Text);
comand.Parameters.AddWithValue("@lname", textBox3.Text);
comand.ExecuteNonQuery();
}
catch(System.Data.SqlClient.SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conection.Close();
}
}
This code is for select from table :
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conection = new SqlConnection("Data Source=.;Initial Catalog=YOUR DATABASE NAME;Integrated Security=True;");
string Sql_Select=("SELECT * FROM YOUR TABLE NAME");
conection.Open();
try
{
SqlCommand comand = new SqlCommand(Sql_Select, conection);
comand.ExecuteNonQuery();
}
catch(System.Data.SqlClient.SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conection.Close();
}
}
And etc.
I hope this is useful for you.