[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# update

Posted on 2014-04-11
5
Medium Priority
?
112 Views
Last Modified: 2014-04-14
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
Comment
Question by:Moti Mashiah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39994409
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
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39994456
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
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39994534
I read some material but still get complicated when I'm trying to write update code.
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39999819
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
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39999820
Excellent as usual
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question