dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersRakesh Chaubey
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » Windows »

I can't change the value in the datagridview.


Posted Date: 07 Jul 2012      Posted By:: John     Member Level: Bronze    Member Rank: 1736     Points: 5   Responses: 1



Dear Forummembers,
I have a problem with changing the data in my datagridview.

I want to give the user the possibility to change a column in the view.
I'll do this with the following code:



Dim Updatecmd As SqlCommand = Cnst.CreateCommand

Updatecmd.CommandText = "Update Klant Set Klant.Naamvoornaam=@Naamvoornaam, Klant.Adres=@Adres, Klant.Huisnummer=@Huisnummer, Klant.Telefoonnummer=@Telefoonnummer, Klant.GSMnummer=@GSMnummer, Klant.Email=@Email, Klant.KlantMaat=@Klantmaat, Klant.TeGoed=@TeGoed where Klantnummer=@Klantnummer"

Updatecmd.Parameters.AddWithValue("Klantnummer", ComboBox1.SelectedValue)

Updatecmd.Parameters.Add("Naamvoornaam", SqlDbType.NVarChar, 40, "Naamvoornaam")

Updatecmd.Parameters.Add("Adres", SqlDbType.NVarChar, 40, "Adres")

Updatecmd.Parameters.Add("Huisnummer", SqlDbType.NVarChar, 15, "Huisnummer")

Updatecmd.Parameters.Add("Telefoonnummer", SqlDbType.NVarChar, 15, "Telefoonnummer")

Updatecmd.Parameters.Add("GSMnummer", SqlDbType.NVarChar, 15, "GSMnummer")

Updatecmd.Parameters.Add("Email", SqlDbType.NVarChar, 50, "Email")

Updatecmd.Parameters.Add("Klantmaat", SqlDbType.NVarChar, 75, "Klantmaat")

Dim I As Integer

For I = 0 To DataGridView1.Rows.Count - 1

Dim TeGoed As String = CStr(DataGridView1.Rows(I).Cells(11).Value)

If (CDbl(TeGoed) <= 0) Then

Updatecmd.Parameters.Add("TeGoed", SqlDbType.NVarChar, 75, "TeGoed")

Else

MessageBox.Show(" You have to fill in a negative value (TeGoed = - 'getal') ")

Exit Sub

End If

Next

DaKlant.UpdateCommand = Updatecmd

DaKlant.Update(TaKlant)


Debugging gives me the following message:

The variable name '@TeGoed' has already been declared. Variable names must be unique within a query batch or stored procedure.

I've searched and tried, but couldn't find a solution?

Somebody can take a look ?

John




Responses

#680326    Author: Nathaniel Nellas Sumaya      Member Level: Silver      Member Rank: 1260     Date: 13/Jul/2012   Rating: 2 out of 52 out of 5     Points: 0

what is your primary key here? TeGoed?


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Tabpages scroll autometic
Previous : Solution for below error.?????
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.