Wednesday, 15 February 2012

mysql - update query not working when i attach the content of text box using data reader on page load -


The code works fine when I remove the page load content, this is a form that the user already has in the database Will allow you to edit existing data. I just want to allow a user to edit the form that he has already submitted. This code is: SqlDataReader Dim n as new SqlCommand DM as the new SQL Connection ("Data Source = Encoder-PC \ SQLEXPRESS; Integrated Security = True") Dim CMD, Com In the form of an integer retardation as D, A, the object handles string as protected sub-page_Load (as the object, byval e, in the form of system event event). Str = "Choose from school * where * rollon = 11" com = new SQL command (str, con) dr = com.ExecuteReader () con.Open () if (dr.Read ()) then Enroll.Text = dr ( "RollNo"). ToString () Name.Text = dr ("name") toastring () class. Text = DR ("class") toasting () and if cone Close () Dr. Close () and sub-protected sub handles (as the sender in the form of object, and events as ARG) [Next]. Click CLICK to CMD. CommodityText = "Update School SET Rollo = '& amp; Nominate. Text & amp;", Name =' "& Name. Text & amp;" ', Class =' ​​& amp; class. Text & amp; "Rollan = 11" CMD.connection = thief con.Open () MsgBox ("The connection is open!") N = cmd.ExecuteNonQuery if n & gt; 0 then MSBBC ("data successfully inserted") other MSBBbox ("Data entry failed") if the catch-out exception is MSBBC (x.tostring ()) at the end in conn. Close (end) end and end

You have tagged your question with MySQL, but in the code you have the sections of SQL Server and Use a connection string for UL. Server.
You should clarify this point. However, during this time I want to answer some errors in your page_load event handler:

First you will need to see if Calling Page_Load is a postback with other controls and avoid reloading the data from that database in that case. Second, open the connection before executing the reader

  dim compatible = "data source = encoder-PC \ SQLEXPRESS; Integrated Security = True "Protects the sub page_load (BYVal sender as the object, byVal E. system .vanterges) handles Me.Load Dim str =" Choose from school * where rollon = 11 "If not then PostPostBack Using C = new SqlConnection (conString) using CMD = New SqlCommand (str, con) con.Open () using DR = com.ExecuteReader () (dr.Read ()) then Enroll.Text = Dr ("RollNo") ToString () Name.Text = dr ("name"). ToString () Class.Text = dr ("class"). Toasting () end if end of end use Ending the use of the end is End  

As you can see, there are other improvements: around the global variable reader and disposable objects for connections, commands and more.

If this code is actually to run against a MySQL database then you need to use the appropriate sections like MySqlConnection, MySqlCommand, MySqlDataReader etc. and connectionstring


No comments:

Post a Comment