I can't figure it out why this code only adds new row but can't save the information in the mysql database.
Code:private void AddParam(MySqlCommand cmd, params string[] cols) { foreach (string col in cols) { cmd.Parameters.Add("@" + col, MySqlDbType.Text, 0, col); } }Code:public int currRec = 0;Code:protected void saveButton_Click(object sender, EventArgs e) { MySqlConnection conn = new MySqlConnection("Data Source=localhost; Database=DB; user id=userdb; password=pass; persist security info=true;"); string sql = "select * from tblUserAccount"; MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds, "tblUserAccount"); DataRow dr = ds.Tables[0].NewRow(); ds.Tables[0].Rows.Add(dr); da.InsertCommand = conn.CreateCommand(); da.InsertCommand.CommandText = "Insert Into tblUserAccount (fname, lname, usernames, passwords, AccountType, priv) " + "Values (@fname, @lname, @usernames, @passwords, @accounttype, @priv)"; AddParam(da.InsertCommand, "fname", "lname", "usernames", "passwords", "accounttype", "priv"); dr.BeginEdit(); dr["fname"] = txtFname.Text; dr["lname"] = txtLname.Text; dr["usernames"] = txtUsername.Text; dr["passwords"] = txtPassword1.Text; dr["accounttype"] = cboAccountType.Text; dr["priv"] = cboPriv.Text; dr.EndEdit(); da.Update(ds, "tblUserAccount"); ds.AcceptChanges(); conn.Close(); conn.Dispose(); }




Reply With Quote