Monday, February 13, 2012

About inserting some parameters to a stored procedure.

Hello everyone,

I am having problem with a program that gets some input from a webform and inserts to a stored procedure, I am getting the two error Error messages below, can somebdoy have a look my code below and put me in the right direction. thanks in advance

Errors

'System.Data.SqlClient.SqlCommand' does not contain a definition for 'InsertCommandType'

'System.Data.SqlClient.SqlCommand' does not contain a definition for 'InsertCommand'

protected void Button1_Click(object sender, EventArgs e) {/* These two variables get the values of the textbox (i.e user input) and assign two local * variables, This is also a good strategy against any Sql Injection Attacks. * */string Interview1 = TextBox1.Text;string Interview2 = TextBox2.Text;string Interview3 = TextBox3.Text;string ProdMentioned = TextBox4.Text;string ProdSeen = TextBox5.Text;string Summary = TextBox6.Text;string Compere = TextBox7.Text;string Duration = TextBox8.Text;//Create Sql connection variable that call the connection string SqlConnection SqlConnection =new SqlConnection(GetConnectionString());//Create a sql command to excute SQL statement against SQL server SqlCommand Command =new SqlCommand();// Set the command type as one that calls a Stored Procedure. Command.InsertCommandType = CommandType.StoredProcedure;//Call the stored procedure so we can pass it on the user input to retrieve user details Command.InsertCommand ="Summaries";//open the command connection with the connection string Command.Connection = SqlConnection;// Pass the user input to the Stored Procedure to check if user exists in our system. Command.InsertParameters.Add("interview1", interview1); Command.InsertParameters.Add("interview2", interview2); Command.InsertParameters.Add("interview3", interview3); Command.InsertParameters.Add("ProdMentioned", ProdMentioned); Command.InsertParameters.Add("ProdSeen", ProdSeen); Command.InsertParameters.Add("Compere", Compere); Command.InsertParameters.Add("Duration", Duration);int rowsAffected = 0;try { rowsAffected = Command.Insert(); }catch (Exception ex) { Resonse.Redirect("InsertSuccessfull.aspx"); }// open the connection with the command //Command.Connection.Open(); }private static string GetConnectionString() {return ConfigurationManager.ConnectionStrings["BroadcastTestConnectionString1"].ConnectionString; }}

not sure about your errors, but I think if you fix those, you will soon get one because

http://peterkellner.net/2006/10/20/loginfailswithiisnotcasini/

Command.InsertParameters.Add("interview1", interview1);

should be

Command.InsertParameters.Add("@.interview1", interview1);

No comments:

Post a Comment