Hi i am updating in database and im getting a "Object reference not set to an instance of an object" Exception.
This is my code :
public void UpdateMember(DataGridView dgv, TextBox t1, TextBox t2, TextBox t3, TextBox t4, TextBox t5, TextBox t6)
{
int i = dgv.CurrentRow.Index;
ds.Tables["dbo.tblMember"].Rows[i]["Name"] = t1.Text;
ds.Tables["tblMember"].Rows[i]["Surname"] = t2.Text;
ds.Tables["tblMember"].Rows[i]["Age"] = t3.Text;
ds.Tables["tblMember"].Rows[i]["Address"] = t4.Text;
ds.Tables["tblMember"].Rows[i]["Email"] = t5.Text;
ds.Tables["tblMember"].Rows[i]["Number"] = t6.Text;
da.Update(ds.Tables["tblMember"]);
MessageBox.Show("Updating Completed", "Updating", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Loading
Shalini JunejaPosted Apr 28, 2011, 12:02 AM
private void RetrieveLedgerInfo()
{
objLedgerInfo.Parameters["Check Voucher"].Value =
txtCVNo.Text;
objLedgerInfo.Parameters["Payee"].Value =
txtPayee.Text;
oleDbConnection1.Open();
objLedgerInfo.ExecuteNonQuery();
oleDbConnection1.Close();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
RetrieveLedgerInfo();
}
and if you are using sql than this code for updation.
Hope this will help you.classPropagateAddsBuilder {static voidMain() {string connString ="server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";string qry = @"select * from employee";SqlConnection conn =newSqlConnection(connString);try{SqlDataAdapter da =newSqlDataAdapter();da.SelectCommand =newSqlCommand(qry, conn);SqlCommandBuilder cb =newSqlCommandBuilder(da);DataSet ds =newDataSet();da.Fill(ds,"employee");DataTable dt = ds.Tables["employee"];// Add a rowDataRow newRow = dt.NewRow();newRow["firstname"] ="y";newRow["lastname"] ="y";dt.Rows.Add(newRow);foreach (DataRow row in dt.Rows){Console.WriteLine("{0} {1}",row["firstname"].ToString().PadRight(15),row["lastname"].ToString().PadLeft(25));}da.Update(ds,"employee");}catch(Exception e) {Console.WriteLine("Error: "+ e);}finally{conn.Close();}}}Sam HobbsPosted Apr 27, 2011, 9:02 PM
Perhaps the table does not exist in your system but it does in your friend's system or perhaps a field in the table does not exist. You will solve the problem very quickly just by looking at theings like that.
Mark FenechPosted Apr 27, 2011, 7:10 AM
omkar mhaiskarPosted Apr 27, 2011, 7:01 AM
just remove dbo from following line.
"ds.Tables["dbo.tblMember"].Rows[i]["Name"] = t1.Text;"
Thanks And Regards
Omkar
Ankit NandekarPosted Apr 27, 2011, 6:44 AM