[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 114
  • Last Modified:

C# update

Hi guys ,

I'm trying to update just one column and I got error see screenshot (app) and also see attachment of my table.

here is my code:

string Query = "update rmsmasterdbtest.dbo.serial set serialnumber='" + this.txtsn.Text + "' ,serialnumber3='" + this.txtstatus + "' where serialnumber='" + this.txtsn.Text + "' ;";

Open in new window

database.JPG
app.JPG
0
Moti Mashiah
Asked:
Moti Mashiah
  • 4
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
I suspect this:
this.txtstatus

Open in new window

Should say:
this.txtstatus.Text

Open in new window

Otherwise it will spit out the object type information, which will exceed the 10 characters that your field will accept.
0
 
Moti MashiahAuthor Commented:
that's is right carl thank you very much and also I just figured that I forgot to add the Reader in my code now all work fine:

Carl , it seems that any time I'm trying to update I got some issue I think that I'm not really understand the concept updating database columns can you give my some explanation also I would like to now what is the difference between these two update methods

1.
string Query = "update RMSCRM.dbo.sales set Status=@Status, note=@note where ID=@id";
            
           

            SqlConnection Myconn = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand(Query, Myconn);

            int SalesID = int.Parse(this.txtid.Text);

            cmd.Parameters.AddWithValue("@id", SalesID);
            cmd.Parameters.AddWithValue("@status", this.txtStatus.Text);
            cmd.Parameters.AddWithValue("@note", this.txtNote.Text);

Open in new window


2.
string Query = "update rmsmasterdbtest.dbo.serial set serialnumber='" + this.txtsn.Text + "' ,serialnumber3='" + this.txtstatus.Text + "' where serialnumber='" + this.txtsn.Text + "' ;";

           
            SqlConnection Myconn = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand(Query, Myconn);
            SqlDataReader Reader;
           

            try
            {
                Myconn.Open();
                Reader = cmd.ExecuteReader();
                MessageBox.Show("Updated Status");
                while (Reader.Read())
                {

                }

Thank you soo much
0
 
Moti MashiahAuthor Commented:
I read some material but still get complicated when I'm trying to write update code.
0
 
Moti MashiahAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for motimash's comment #a39994534
Assisted answer: 500 points for carl_tawn's comment #a39994409

for the following reason:

Thanks
0
 
Moti MashiahAuthor Commented:
Excellent as usual
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now