troubleshooting Question

VS 2008 c# windows application user entry form

Avatar of Gracie2012
Gracie2012 asked on
Microsoft SQL Server.NET ProgrammingMicrosoft Development
3 Comments1 Solution363 ViewsLast Modified:
I want to know the best way to execute a stored procedure from a c# windows application user entry form.  Simply, insert records into a table.  The most basic.  I've tried using the binding navigation and putting code behind the "+" and that did not work so I am thinking of just going with simple text boxes which will hold the parameters to be passed to the sql procedure.  That is not working either.  Can someone point me in the direction of either how to get what I have working or a better way to do this.  I have the insert statement in the code below to make it simple but ideally I'd call my procedure instead.  I will say I am very inexperienced at c# programming.  No error, the insert just never happens.

private void button1_Click(object sender, EventArgs e)
        {
            SqlCommand dbCommand = new SqlCommand();
            //dbCommand.CommandText = "InsCustomer";  <-----stored proc
            //dbCommand.CommandType = CommandType.StoredProcedure;
            string sqlQuery = "INSERT INTO Customer (Utility, CustID)";
            sqlQuery += " VALUES (@Utility, @CustID)";
            string connectionstring = ("blah blah blah");

            using (SqlConnection dataConnection = new SqlConnection(connectionstring))
            using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
            {
                dataConnection.Open();

                dataCommand.Parameters.AddWithValue("Utility", textBox1.Text);
                dataCommand.Parameters.AddWithValue("CustID", textBox2.Text);

            }
        }
    }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros