Hi,
i am having problem in updating my database although i can upadate my dataset

private void btnSave_Click(object sender, EventArgs e)
        {
            DataRow dRow = ds1.Tables["ContainerID"].NewRow();

            dRow[1] = textBox1.Text;
            dRow[2] = textBox2.Text;
            dRow[3] = textBox3.Text;

            ds1.Tables["ContainerID"].Rows.Add(dRow);

            MaxRows = MaxRows + 1;
            inc = MaxRows - 1;

            MessageBox.Show("Entry Added");
        }

but while updating database it gives an error
The ConnectionString property has not been initialized.

private void btnSave_Click(object sender, EventArgs e)
        {            
            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);

            DataRow dRow = ds1.Tables["ContainerID"].NewRow();

            dRow[1] = textBox1.Text;
            dRow[2] = textBox2.Text;
            dRow[3] = textBox3.Text;

            ds1.Tables["ContainerID"].Rows.Add(dRow);

            MaxRows = MaxRows + 1;
            inc = MaxRows - 1;

            da.Update(ds1, "ContainerID");
            //ds1.AcceptChanges();
            MessageBox.Show("Entry Added");
        }

how can i Update my database?
Thanks.

public Form1()
        {
            InitializeComponent();
        }
        SqlConnection con;
        DataSet ds1;
        SqlDataAdapter da;
        int MaxRows = 0;
        int inc = 0;

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection();
            ds1 = new DataSet();
            con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\IMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

            con.Open();

            string sql = "SELECT * From Container";
            da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
            da.Fill(ds1, "ContainerID");
            NavigateRecords();
            MaxRows = ds1.Tables["ContainerID"].Rows.Count;

            con.Close();


            con.Dispose();
        }

Line 28 you dispose of the connection. You'll have to recreate it. And your latest post is no help at all. What error, what code?

This article has been dead for over six months. Start a new discussion instead.