C# issue “Object reference not set to an instance of an object”.

Hi,

I'm having an issue with my C# code. I m trying to insert data into my database from a form, unfortunately I keep getting issues with "Object reference not set to an instance of an object".

Here s the code:

protected void InsertMovie(object sender, EventArgs e) { SqlConnection Connection = new SqlConnection(CONNECTION_STRING); Connection.Open(); SqlCommand Command = new SqlCommand(@"INSERT INTO Members (MembershipID, FirstName, LastName, DOB) VALUES ( 0 , @FirstName, @LastName)", Connection); TextBox txtFname = (TextBox)pnlDisplay.FindControl("InsertF... TextBox txtLname = (TextBox)pnlDisplay.FindControl("InsertL... Command.Parameters.AddWithValue("@FirstN... txtFname.Text); Command.Parameters.AddWithValue("@LastNa... txtLname.Text); Command.ExecuteNonQuery(); Connection.Close(); GenerateForm(); } The issue I m having is on the line "Command.Parameters.AddWithValue("@First... txtFname.Text);". 

Anybody have any ideas?

by Albatraozz via /r/csharp

Leave a Reply