Groups > Databases > MySQL for ASP.NET > Re: Updating field in a table using C#




Updating field in a table using C#

Updating field in a table using C#
Thu, 28 Feb 2008 22:47:56 +000
Hi,

My problem is quite a simple one but is difficult to explain. I am selecting a
value from a table and in order to display it in a textbox I first have to store
it in a session variable, and then put the textbox = session variable. This
works fine,and is done in my page load.

Where my problem lies is; on the same page I want to edit the value in the
textbox and click the update button thus updating the field in the database to
whatever is entered in the textbox. 

Is this possible?When I run the page it won't update the value in the textbox to
whatever it has been changed to.

Any suggestions greatly appreciated!
Post Reply
Re: Updating field in a table using C#
Thu, 28 Feb 2008 23:55:48 +000
upon the button click event you update first your table and then your session
variable.
Post Reply
Re: Updating field in a table using C#
Fri, 29 Feb 2008 00:48:38 +000
That is what I'm doing. the variable is assigned in the page load so when I
click update it's the table I'm updating. I'm not touching the variable
Post Reply
Re: Updating field in a table using C#
Fri, 29 Feb 2008 08:44:54 +000
Could you please post your code sample.
Post Reply
Re: Updating field in a table using C#
Fri, 29 Feb 2008 16:16:04 +000
Hi,

In my page load I have;

myConn = new OdbcConnection("Driver={MySQL ODBC 3.51
Driver};Server=localhost;Database=KDL;User=root;Password=password;");

            myConn.Open();
            string sql = "select Manager_Name from tbluser where Team_ID =
?";
            OdbcCommand cmd = new OdbcCommand(sql, myConn);


            cmd.Connection = myConn;
            cmd.Parameters.AddWithValue("@TeamID",
Session["TeamID"].ToString());

            MyReader = cmd.ExecuteReader();

            if (MyReader.Read())
            {
                Session["ManagerName"] =
MyReader["Manager_Name"];
                txtManager.Text = Session["ManagerName"].ToString();
                MyReader.Close();
            } 

 And then under the button click I have;

myConn = new OdbcConnection("Driver={MySQL ODBC 3.51
Driver};Server=localhost;Database=KDL;User=root;Password=shane34279;");

            myConn.Open();
            string sql = "UPDATE tbluser SET Manager_Name = '"+
txtManager.Text +"' WHERE Team_ID = ?";
            OdbcCommand cmd = new OdbcCommand(sql, myConn);


            cmd.Connection = myConn;

            cmd.Parameters.AddWithValue("@TeamID",
Session["TeamID"].ToString());
            

            MyReader = cmd.ExecuteReader();
            MyReader.Close();
            Response.Redirect("Login.aspx");
Post Reply
about | contact