Inserting into MySQL database from C# Webforms, give ArgumentException -
I am trying to create a registration page through a web page that will connect to a MySQL databse and insert data , But it puts an argument exception (even if I believe I'm following the tutorial at all) and will not include the data in the table.
My C # code for the registration page is as follows:
Public partial class registration: system. Web. UI page {MySql.Data.MySqlClient.MySqlConnection conn; MySql.Data.MySqlClient.MySqlCommand CMD; String query STR; Secure Zero Page_load (Object Sender, EventAgps E) {} Safe Weather Register Aventim (Object Sender, EventArgus E) {Register User (); } Private Zero Register User () {string connString = System.Configuration.ConfigurationManager.ConnectionStrings ["WebAppConnString"]. ToString (); Conn = New MySql.Data.MySqlClient.MySqlConnection (connString); conn.Open (); QueryStr = ""; Include QueryStr = "seniorschema.registration (password 1, email, first name, last name, password 2, code)" + "value ('" + password reader box 1. text + "," "+ email textbox. Text + "','" + First name text box. Text + "','" + Last name textbox. Text + "','" + password textbox. Text + "','" + CodeTextBox.Text + "')"; CMD = New MySql.Data.MySqlClient.MySqlCommand (queryStr, conn); cmd.ExecuteReader (); conn.Close ();}} And my connection to WebConfig file is here: < / p>
& lt; connectionStrings & gt; & lt; add name = "w EbAppConnString "connectionString =" server = localhost; Id = webware; pwd = password; Database = Senior Summary; "ProviderName =" MySql.Data.MySqlClient "/> & lt; / ConnectionStrings & gt; Any help would be most appreciated thanks!
I do not know what tutorial you've read but should never teach them to use string combination Create a SQL command text.
However, the error you get is from connectionstring.
You should write
string connString = Configu RationManager.ConnectionStrings ["WebAppConnString"]. Connection String; There is an error in the definition of connection string in web.config (a typo?) This uid = .... No id = ..... And how do I enter here, which adds the record.
MySql.Data Using .MySqlClient;; queryStr = @ "insert in seniorschema.registration (password1, email, first name, last name, password2, code) values (@pwd, @email, @first, @last, @ pwd2) , Using @code ", (MySqlConnectionCon = New MySqlConnection (connString)) (MySq LCommand cmd = New MySqlCommand (queryStr, Connecticut) {conn.Open (); Cmd.Parameters.AddWithValue ("@ pwd", PasswordTextBox1.Text); cmd.Parameters.AddWithValue ("@email", EmailTextbox.Text); Cmd.Parameters.AddWithValue ("First", firstNameTextBox.Text); cmd.Parameters.AddWithValue ("Last @", LastNameTextBox.Text); Cmd.Parameters.AddWithValue ("@ pwd2", PasswordTextBox2.Text); cmd.Parameters.AddWithValue ("@ code", CodeTextBox.Text); Integer rowAdded = cmd.ExecuteNonQuery ();} This approach combines all the complexities needed to code the quotation marks around the values away from the values;
Finally, but it is actually a logic that is very broad and is not immediately related to your question.
If a copy or a copy of a registration table can be used to store a password in clear text, from a bad practice, from a security perspective, clear text, then it will be able to read the passwords of all registered users. There are proven methods that make them unreadable to the audience
Comments
Post a Comment