Please tell me what is wrong in my update code

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 11
Reputation: prasu is an unknown quantity at this point 
Solved Threads: 1
prasu's Avatar
prasu prasu is offline Offline
Newbie Poster

Please tell me what is wrong in my update code

 
0
  #1
Jun 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

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

 
0
  #2
Jun 18th, 2008
Are you getting any error messages?

Could you post them and the line numbers?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: prasu is an unknown quantity at this point 
Solved Threads: 1
prasu's Avatar
prasu prasu is offline Offline
Newbie Poster

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

 
0
  #3
Jun 18th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

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

 
0
  #4
Jun 18th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: junglee_99 is an unknown quantity at this point 
Solved Threads: 1
junglee_99 junglee_99 is offline Offline
Newbie Poster

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

 
0
  #5
Jun 27th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: prasu is an unknown quantity at this point 
Solved Threads: 1
prasu's Avatar
prasu prasu is offline Offline
Newbie Poster

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

 
0
  #6
Jun 28th, 2008
I got it.

Thanks!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC