Execute Stored Procedure From Form
I have created and tested a stored procedure that works in sql. This stored procedure has one parameter that it requires to run "quoteno" . I already have the database attached to the form. Can anyone help me with the code for this. The name of my stored procedure is EstimateApproval and my database name is Estimator.
Thanks. Ive looked for answers on the net but not having any luck
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Please search this forum, this has been answered a number of times before.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Please search this forum, this has been answered a number of times before.
This is what i have tried. I get no errors but the database is not changing as per the stored procedure which does work when run within sql.
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Please search this forum, this has been answered a number of times before.
This is what i have tried. I get no errors but the database is not changing as per the stored procedure which does work when run within sql.
private void approveestBN_Click(object sender, EventArgs e)
{
int @estno;
int.TryParse(startestnoCB.Text,out estno);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "EstimateApproval";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@estno", SqlDbType.Int);
}
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
If the form is attached to the database through table adapters do I have to make another SqlConnection assignment?
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
I have tried this but Im now getting an error saying that "Format of the initialization string does not conform to specification starting at index 0."
private void approveestBN_Click(object sender, EventArgs e)
{
int @estno;
int.TryParse(startestnoCB.Text,out estno);
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "estimateDataSet";
cmd.Connection = conn;
cmd.CommandText = "EstimateApproval";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@estno", SqlDbType.Int);
cmd.ExecuteReader();
}
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Thanks so much for hanging in with me. I now get an error that I cannot log into the database. I know that the solution already logs in with integrated security and I'm able to manipulate data in the data base on the form. Now when I try to execute the stored procedure through the database connection you gave me I'm not able to connect. Could it be because im already connected???
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Jerry I have been fumbling with this code you gave me for days and I cannot figure out how to change it to get the return value @quotenum from the sql stored procedure. Can you help me please.
MJV
Junior Poster in Training
67 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0