This is my code to generate an autogenerating jobcode and fill it in a text box
public void newjobecodenoget(){
String jobcodeno = null;
OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
oleDbConnection1.Open();
String query = "SELECT TOP 1 jobpk FROM jobcodemastertable ORDER BY jobpk DESC";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
DataSet ds = new DataSet();
dAdapter.Fill(ds, "tbljobrdataview");
Int32 S = int.Parse(ds.Tables[0].Rows[0][0].ToString());
S++;
jobcodeno = "NFT" + S.ToString();
MessageBox.Show( jobcodeno);
txtjobcode.Text = "NFT" + S.ToString();
}
but Iam getting exception at the last line ie txtjobcode.Text = “NFT” + S.ToString();
Object reference not set to an instance of an object.
all other things are fine and jobcode is generated and shown in message box
can anyone help pls
my txtjobecode was declared as
private void InitializeComponent()
{
this.txtjobcode = new System.Windows.Forms.TextBox();
//
// txtjobcode
//
this.txtjobcode.Location = new System.Drawing.Point(98, 23);
this.txtjobcode.Name = "txtjobcode";
this.txtjobcode.Size = new System.Drawing.Size(91, 20);
this.txtjobcode.TabIndex = 0;
//
}
Obviously,
txtjobcodeis null. Since I do not see wheretxtjobcodeis declared and assigned to, I cannot tell you why it is null.