c# - Trouble opening SQL connection to insert textbox values -


First of all, I want to say that this is the most spectacular platform I have encountered in my programming journey, and I last In all three months, Google-phishing for all help. Great support and even more and more styles #uncromancer badges

Enough with flattering

I am projecting practice, insurance website now , I need to get user input from the text box in the database. I've seen lots of related questions here but I'm getting an error message on my connection I have not got on any of the other posts, and I'm so ignorant that it is difficult to implement the example that does not fit actually What am i in (As a side note, my trainer specifically wants the most basic form of this code, and such a way to tell me the answer here is not much to worry about parameterizing questions for security Or to use a try hold block for exceptions, but for those signals)

I have a SQL user because of a failure in starting the process for example Failed to generate a user instance of Servers requires. The connection will be closed. " Error message

Am I doing my syntax wrong? Am I using the 'Textbox1.Text' value? Am I very stupid to do this?

  using the system; Using System.Text; Using System.Collections.Generic; Using System.Linq; Using System.Data; Using System.Data.Sql; Using System.Data.SqlClient; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Public Partial Submission SubmissionPage:. System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {} protected void Button1_Click (object sender, EventArgs e) {string connectionstring = @ "Data Source = \ SQLEXPRESS; AttachDbFilename = C: \ aspnetdb.mdf ; Integrated security = true; user instance = true "; SqlConnection sqlConn = New SqlConnection (connectionString); SqlConn.Open (); String thisQuery = "putting the customer (" + "name, SIC_NAIC, address, city, state, zip," + ") values ​​(" + "@ TextBox1.Text, @ RadioButtonList1.SelecedItem, @ TextBox2.Text, @ DropDownList1 Selected Indem, @ text box 3. Text "+") "; SqlCommand this command = new SqlCommand (this jQuery, sqlConn); ThisCommand.ExecuteNonQuery (); SqlConn.Close (); }}    

Check it out and use the sql parameter:

  using (var conn = new SqlConnection ( "data source =. \ SQLEXPRESS; initial catalog = aspnetdb; integrated Security = true; connect timeout example 30; user = true")) {conn.Open ( ); (Siardiaansiaisiai) values ​​(@ name, @ Saisi_anaaisi) Make (var using cmd = new SQL Command () attempts) (try {cmd.Parameters.Add ( "@ name", SQLDbType.VarChar, 50). Value = throw TextBox1.Text; Cmd.Parameters.Add ( "@ SIC_NAIC", SQlDbType.VarChar, 50) .Value = RadioButtonList1.SelecedItem.ToString (); cmd.ExecuteNonQuery ();} catch (exception) {{}; } finally {if (conn.State == ConnectionState.Open) conn.Close (in);}}   

Make sure you've downloaded sqlmanagement Studio 2008 express .. and then Attach asp.netdb and add your sqA Change the connection string.

Regards

Comments