private void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=LoginDB;Integrated Security=True");
con.Open();
SqlCommand commamd = new SqlCommand("insert into tblUser values ('"+string.Format(txtUser.Text)+"' , '"+ txtServer.Text+"' , '"+txtpwd.Text+"', getdate())" ,con );
commamd.ExecuteNonQuery();
MessageBox.Show("Successfully Inserted");
con.Close();
BindData();
}
void BindData()
{
SqlCommand command = new SqlCommand("select * from tblUser" ,con);
SqlDataAdapter sd = new SqlDataAdapter();
DataTable dt = new DataTable();
sd.Fill(dt);
dataGridView.DataSource = dt;
}
I face error in new sqlcommand query. Please help me with this.