Gracie2012
asked on
VS 2008 c# windows application user entry form
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.StoredProcedur e;
string sqlQuery = "INSERT INTO Customer (Utility, CustID)";
sqlQuery += " VALUES (@Utility, @CustID)";
string connectionstring = ("blah blah blah");
using (SqlConnection dataConnection = new SqlConnection(connectionst ring))
using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
{
dataConnection.Open();
dataCommand.Parameters.Add WithValue( "Utility", textBox1.Text);
dataCommand.Parameters.Add WithValue( "CustID", textBox2.Text);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand dbCommand = new SqlCommand();
//dbCommand.CommandText = "InsCustomer"; <-----stored proc
//dbCommand.CommandType = CommandType.StoredProcedur
string sqlQuery = "INSERT INTO Customer (Utility, CustID)";
sqlQuery += " VALUES (@Utility, @CustID)";
string connectionstring = ("blah blah blah");
using (SqlConnection dataConnection = new SqlConnection(connectionst
using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
{
dataConnection.Open();
dataCommand.Parameters.Add
dataCommand.Parameters.Add
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had resolved this yesterday but that was the correct answer, I had not called the execute method.... I'm only giving this a C though because it does not really explain then how to do this, like I said, I'm very new..
but might you just missed @ before parameter adding
check code.
Open in new window