private DataSet GetDataByName(string Name)
{
SqlConnection conn =new SqlConnection ( "Data Source=VU-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
conn.Open();
SqlCommand comm =new SqlCommand( "Select * from Table where Name = " + Name,conn);
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = comm ;
DataSet myDataSet = new DataSet();
myAdapter.Fiill(myDataSet);
conn.Close();
return myDataSet
}
private void InsertInDB()
{
if(GetDataByName(this.txtName.Text).Tables[0].Rows.Count == 0)
{
SqlConnection conn =new SqlConnection ( "Data Source=VU-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
conn.Open();
SqlCommand comm =new SqlCommand( "INSERT INTO connect_com "+"(name,E_mail,School) "+" VALUES("+txtName.Text+"','"+"','"+txtEmail.Text+"','"+txtSchool.Text+")",conn);
}
comm.ExecuteNonQuery();
conn.Close();
}
should it help you?