troubleshooting Question

Updating a MS SQL database

Avatar of pclarke7
pclarke7 asked on
Microsoft SQL ServerC#ASP.NET
19 Comments1 Solution360 ViewsLast Modified:
I am having problems updating my MS SQL database from my C# application. I can read from the database but my updates do not work. Below is an example

I have a value of 'AAA' in field BM_BadgeID. When I run the select statement below it returns 'AAA' as expected to variable LastTran. Then when the Update statement runs it would seem to update the value to 'TEST-7' - however when I inquire on the database it is still set to 'AAA'

If I run this code a 2nd time then the select returns TEST-7 to field LastTran (as though it were updated on the database) . However if I end the application and restart the value is back to 'AAA'.

I don't understand what I am doing incorrectly. Any help/advise would be appreciated.

            //Basic SELECT method to populate a DataSet from a SqlDataAdapter
            ConnectionStr = globals.MyTrans.p1_RtvConnMSSQLDB_NATIVE;
            SqlConnection sqlConn = new SqlConnection(ConnectionStr);
            SqlDataAdapter sqlAdapt = new SqlDataAdapter("SELECT * FROM badge_master  WHERE BM_BadgeID='123123'",sqlConn);
            SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(sqlAdapt);
            DataSet sqlSet = new DataSet();
            sqlAdapt.Fill(sqlSet, "badge_master");
            DataRow dRow = sqlSet.Tables["badge_master"].Rows[0];
            string name = dRow.ItemArray.GetValue(1).ToString();            // Badge Name
            string LastTran = dRow.ItemArray.GetValue(11).ToString();       // Last Transaction name

            //Basic UPDATE method with Parameters
            ConnectionStr = globals.MyTrans.p1_RtvConnMSSQLDB_NATIVE;
            SqlCommand sqlComm = new SqlCommand();
            sqlComm = sqlConn.CreateCommand();
            sqlComm.CommandText = "Update badge_master set BM_LastTranName='TEST-7' where BM_BadgeID='123123'";
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros