Click here to Skip to main content
15,896,726 members

Response to: binding sql dataset using

Revision 1
Update your code like this

C#
private void btnSave_Click(object sender, EventArgs e)
{
  string s = dtpdue_date.Value.ToString();
  string s1 = dtpcompletiondate.Value.ToString();
           
  string connectionstr = "Data Source=TUSHAR-PC;Initial Catalog=callcenter;Persist Security Info=True;User ID=sa;Password=password@123";
  string sql = "Insert into tasks(t_id,Name,Priority,status,Due_date,description,date of completion) values('"+txtT_id.Text+"','"+txtname.Text+"','"+cbopriority.Text+",'"+cboStatus.Text+"','"+ s+"','"+txtcomments.Text+"'.'"+s1+"')";
    
 DataSet dataSet = new DataSet();
 using (SqlConnection connection =
        new SqlConnection(connectionstr))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(
            queryString, connection);
        adapter.Fill(dataset);
        dataGridView1.DataSource = dataset;
    }
}
make sure that your connection string is in proper order.
Posted 14-Jan-13 9:37am by Jibesh.
Tags: ,