Welcome to Dream.In.Code
Become an Expert!

Join 150,417 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,053 people online right now. Registration is fast and FREE... Join Now!




Update command

 
Reply to this topicStart new topic

Update command, Update

ryan john majarais
3 Apr, 2008 - 11:18 AM
Post #1

New D.I.C Head
*

Joined: 3 Apr, 2008
Posts: 5



Thanked: 1 times
My Contributions
my Database is MS Sql 2005 asp.net environment vb.net coding. im developing a website for my thesis and i need help to solve my problem.

my update code did not work only a msgbox box pop up but it did not edit the data. what is wrong? pls send me a correct code thanks...[/color]
CODE
Protected Sub cmdEdit_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
      

        Dim connString As String = _
                       ConfigurationManager.ConnectionStrings("connstr").ConnectionString
        Dim cnn As New SqlClient.SqlConnection(connString)

        Try
            cnn.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try




        Dim sql As String = "update VotingCandidateRegistration set 'forFname','forSurname','ForMI','forParty' where VotingCandidateRegistration=('" & txtforStdntNo.Text & "', '" & txtforFname.Text & "','" & txtforSurname.Text & "','" & txtMI.Text & "','" & txtParty.Text & "')"
        Dim cmd As New SqlClient.SqlCommand(sql, cnn)






        MsgBox("Record has been edited")

        cnn.Close()
    End Sub

User is offlineProfile CardPM
+Quote Post

orcasquall
RE: Update Command
5 Apr, 2008 - 04:46 AM
Post #2

D.I.C Head
Group Icon

Joined: 14 Sep, 2007
Posts: 158



Thanked: 3 times
Dream Kudos: 50
My Contributions
Try adding this
vb
cmd.ExecuteNonQuery()


So it's somewhere in your code like so
vb

Dim sql As String = "update VotingCandidateRegistration set 'forFname','forSurname','ForMI','forParty' where VotingCandidateRegistration=('" & txtforStdntNo.Text & "', '" & txtforFname.Text & "','" & txtforSurname.Text & "','" & txtMI.Text & "','" & txtParty.Text & "')"
Dim cmd As New SqlClient.SqlCommand(sql, cnn)
cmd.ExecuteNonQuery()


And I think your update statement is wrong. Try writing a working version of the update statement in the database, and then port the statement into your ASP.NET code.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Update Command
5 Apr, 2008 - 05:04 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
He is correct, you update statement is way off from what it should be. You can read about the structure of a SQL UPDATE statement here. In the meantime I modified your statement


vb

Dim sql As String = "update VotingCandidateRegistration " _
"SET forFName = '" + txtForFname.Text + "'," _
"forSurname = '" + txtForSurname.Text + "'," _
"forMI = '" + txtMI.Text + "', " _
"forParty = '" & txtParty.Text + "'" _
" WHERE VotingCandidateRegistration = " + Convert.ToInt32(txtForStdntNo.Text)

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month