943,928 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1063
  • VB.NET RSS
Jun 18th, 2008
0

Please tell me what is wrong in my update code

Expand Post »
Please Check the code and reply what is wrong in the update code
Try block is executed successfully........but it is not being updated.



Public Class Form3
Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=attend_ap; User=root;Password=;")
Dim cmd, cmd2 As Odbc.OdbcCommand
Dim adp, adp2 As Odbc.OdbcDataAdapter
Dim ds, ds2 As New DataSet

Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form1.Close()

End Sub

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

cn.Open()
cmd = New Odbc.OdbcCommand
cmd.Connection = cn
cmd.CommandText = "Select * from " & Form1.TextBox2.Text & "_att"
ds = New DataSet
adp = New Odbc.OdbcDataAdapter(cmd)

Try
adp.Fill(ds, Form1.TextBox2.Text & "_att")
Catch ex As Exception
MsgBox("Invalid Table name")
Me.Close()
End Try

Me.DataGridView1.DataSource = ds
Me.DataGridView1.DataMember = Form1.TextBox2.Text & "_att"

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
Form2.Show()
End Sub


Private Sub Form3_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
cmd2 = New Odbc.OdbcCommand
cmd2.Connection = cn
cmd2.CommandText = "Select * from " & Form1.TextBox2.Text & "_att"
ds2 = New DataSet
adp2 = New Odbc.OdbcDataAdapter(cmd2)
Try
adp2.Fill(ds2, Form1.TextBox2.Text & "_att")

Catch ex As Exception
MsgBox("Invalid Table name")
Me.Close()


End Try

Me.DataGridView1.DataSource = ds2
Me.DataGridView1.DataMember = Form1.TextBox2.Text & "_att"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)
' Dim cmdbuilder2 As New Odbc.OdbcCommandBuilder(adp2)
Try
i = adp.Update(ds, Form1.TextBox2.Text & "_att")
' cmd.ExecuteNonQuery()
' i = adp2.Update(ds2, Form1.TextBox2.Text & "_att")
MsgBox("records updated sucessfully")

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Me.Label2.Text = Form1.TextBox2.Text
End Sub

End Class
Similar Threads
Reputation Points: 13
Solved Threads: 1
Newbie Poster
prasu is offline Offline
11 posts
since Jun 2008
Jun 18th, 2008
0

Re: Please tell me what is wrong in my update code

Are you getting any error messages?

Could you post them and the line numbers?
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jun 18th, 2008
0

Re: Please tell me what is wrong in my update code

For the code i have posted there is no error message
it shows updated successfully....but it is not updating it

if i comment the whole form3_visiblechanged function then error
in 77th line i.e
i = adp.Update(ds, Form1.TextBox2.Text & "_att")
in the try block of the button1_click

error message is:
dynamic generation for the update command is not supported against a select command that does not return any key column information.
Reputation Points: 13
Solved Threads: 1
Newbie Poster
prasu is offline Offline
11 posts
since Jun 2008
Jun 18th, 2008
0

Re: Please tell me what is wrong in my update code

I suggest you use the same Command Object (cmd) , the same Adapter (adp) and the same Dataset (ds) in the code for event Form3_VisibleChanged.

Try it and let me know if it worked.
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jun 27th, 2008
0

Re: Please tell me what is wrong in my update code

Perhaps you need to use single quotes in your sql string?

eg:
"SELECT * FROM Table WHERE TEXTID = ' " & me.Textbox.TEXT & " ' ORDER BY DATE"

Hope that helps
Reputation Points: 10
Solved Threads: 1
Newbie Poster
junglee_99 is offline Offline
1 posts
since Jun 2008
Jun 28th, 2008
0

Re: Please tell me what is wrong in my update code

I got it.

Thanks!
Reputation Points: 13
Solved Threads: 1
Newbie Poster
prasu is offline Offline
11 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: WSDL SOAP
Next Thread in VB.NET Forum Timeline: Newbie need help with filtering/showing data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC