[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Inserting Data Issue C#

I am trying the following code to insert data using C#.  The data does not get inserted and just refreshes.  Not sure if you guys/gals can see a problem that I am missing:

               string DescriptionValue = TextBox1.Text;
                string CategoryValue = DropDownList2.SelectedValue;
                System.Data.SqlClient.SqlConnection sqlConnection3 = new System.Data.SqlClient.SqlConnection("Data Source=my connection string");
                sqlConnection3.Open();
                
                System.Data.SqlClient.SqlCommand cmd2 = new System.Data.SqlClient.SqlCommand();
                cmd2.CommandType = System.Data.CommandType.Text;
                cmd2.CommandText = "INSERT Item (Barcode, Description, Store, StorePart, TotalOnHandNeeded, TotalEachLocationNeeded, TotalEachLocationNeeded2, Category, Type, WhereUsedFor, URL, Note) VALUES ('" + BarcodeValue + "', '" + DescriptionValue + "', Null, Null, Null, Null, Null, '" + CategoryValue + "', Null, Null, Null, Null)";
                cmd2.Connection = sqlConnection3;

                
                cmd2.ExecuteNonQuery();
                sqlConnection3.Close();
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Item Successfully Added');", true);
                Barcode.Text = "";
                DropDownList2.SelectedValue = "Select One";
                TextBox1.Text = ""; 

Open in new window

0
jjrr007
Asked:
jjrr007
  • 2
1 Solution
 
Mandeep SinghDatabase AdministratorCommented:
try

cmd2.CommandText = "INSERT into Item (Barcode, Description, Store, StorePart, TotalOnHandNeeded, TotalEachLocationNeeded, TotalEachLocationNeeded2, Category, Type, WhereUsedFor, URL, Note) VALUES ('" + BarcodeValue + "', '" + DescriptionValue + "', Null, Null, Null, Null, Null, '" + CategoryValue + "', Null, Null, Null, Null)";

Open in new window

0
 
jjrr007Author Commented:
I found the answer.  It was in the column name actually.
0
 
jjrr007Author Commented:
I found the answer on my own.  I had the wrong column name.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now