Object reference not set to an instance of an object.
-
hi friends, i'm using vb.net for devloping a web application. my code shows nothing wrong. but when i click a button to add the entries this error is being shown. my other applications are also developed in the same manner but they do not show error. the only difference in this application is that i'm tring to enter data into database from text property of a label. can this be a cause. i'm unable to figure out please help me. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 198: If DropDownList1.SelectedItem.Text = "Not Available" Then Line 199: insert = "INSERT INTO Transmittal(Project_Name, Username, [Date], [To], Kind_Attn, Title, Drw_Doc_Num, Copies, Rev_Num, Action)" + "VALUES ('" + TextBox7.Text + "', '" + Label10.Text + "', '" + Label17.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox8.Text + "', '" + TextBox5.Text + "', '" + TextBox6.Text + "' )" Line 200: OleDbDataAdapter1.InsertCommand.CommandText = (insert) Line 201: OleDbDataAdapter1.InsertCommand.ExecuteNonQuery() Line 202: OleDbConnection1.Close() Source File: C:\Inetpub\wwwroot\OM\trans.aspx.vb Line: 200 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] OM.trans.Button4_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\OM\trans.aspx.vb:200 System.Web.UI.WebControls.Button.onclick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1263
-
hi friends, i'm using vb.net for devloping a web application. my code shows nothing wrong. but when i click a button to add the entries this error is being shown. my other applications are also developed in the same manner but they do not show error. the only difference in this application is that i'm tring to enter data into database from text property of a label. can this be a cause. i'm unable to figure out please help me. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 198: If DropDownList1.SelectedItem.Text = "Not Available" Then Line 199: insert = "INSERT INTO Transmittal(Project_Name, Username, [Date], [To], Kind_Attn, Title, Drw_Doc_Num, Copies, Rev_Num, Action)" + "VALUES ('" + TextBox7.Text + "', '" + Label10.Text + "', '" + Label17.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox8.Text + "', '" + TextBox5.Text + "', '" + TextBox6.Text + "' )" Line 200: OleDbDataAdapter1.InsertCommand.CommandText = (insert) Line 201: OleDbDataAdapter1.InsertCommand.ExecuteNonQuery() Line 202: OleDbConnection1.Close() Source File: C:\Inetpub\wwwroot\OM\trans.aspx.vb Line: 200 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] OM.trans.Button4_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\OM\trans.aspx.vb:200 System.Web.UI.WebControls.Button.onclick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1263
First, before I answer your question I am going to send you off to read an article about writing secure SQL Code. The reason for this is that your code is very heavily susceptable to a SQL Injection Attack. SQL Injection Attacks and Some Tips on How to Prevent Them[^] manik nath wrote: OleDbDataAdapter1.InsertCommand.CommandText = (insert) There are three possibilities here, one of which I'm discounting because the previous line creates the value. Possibility 1: OleDbDataAdapter1 is null Possibility 2: The InsertCommand property on OleDbDataAdapter1 is null. Does this help?
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
-
First, before I answer your question I am going to send you off to read an article about writing secure SQL Code. The reason for this is that your code is very heavily susceptable to a SQL Injection Attack. SQL Injection Attacks and Some Tips on How to Prevent Them[^] manik nath wrote: OleDbDataAdapter1.InsertCommand.CommandText = (insert) There are three possibilities here, one of which I'm discounting because the previous line creates the value. Possibility 1: OleDbDataAdapter1 is null Possibility 2: The InsertCommand property on OleDbDataAdapter1 is null. Does this help?
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
hi colin, i did not get you exactly, what did you want to say. please could you elaborate both the posiibilities a little more.