Results 1 to 16 of 16

Thread: having error at updating database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Smile having error at updating database

    hello frnds this is my code i m having problem while updating my database... In this code when i delete records then it will deleted but it can't show updated data..for viewing new updated data i hav to again open the form ... so is there any code which i miss??? to update database @ runtime??
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\SmS Application\New.mdb")
            Dim cmd As New OleDbCommand
            Dim ds As New DataSet
            Dim DataSet1 As New DataSet
            Dim cmdOLEDB As New OleDbCommand
            Dim cmdInsert As New OleDbCommand
            Dim cmdUpdate As New OleDbCommand
            Dim cmdDelete As New OleDbCommand
            
            Dim delete As New OleDb.OleDbCommand("delete INTO Table2 (PhoneNumber,Message,Dates) VALUES (@PhoneNumber,@Message, now())", con)
    
            Dim adapter As New OleDb.OleDbDataAdapter("SELECT  PhoneNumber, Message  FROM Table2", con)
            con.Open()
            cmdDelete.CommandType = CommandType.Text
            cmdDelete.Connection = con
            If (MessageBox.Show("Are u sure want to delete ehere id = " & TextBox1.Text, "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
                cmdDelete.CommandText = "DELETE FROM Table2 WHERE ID = " & TextBox1.Text
                cmdDelete.ExecuteNonQuery()
                MessageBox.Show("         Records Deleted!!            ")
           Else
            End If
            Exit Sub
            cmdDelete.Dispose()
            adapter.Update(DataSet1, "table2")
           con.Close()
        End Sub

  2. #2
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Re: having error at updating database

    to determine whether the data has been deleted, use:
    vb Code:
    1. cmdDelete.CommandText = "DELETE FROM Table2 WHERE ID = " & cint( TextBox1.Text )
    2.  
    3. Dim iRs As Integer = cmdDelete.ExecuteNonQuery()
    4. if iRs > 0 then
    5.     MessageBox.Show("         Records Deleted!!            ")
    6. end if

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Re: having error at updating database

    I havn't got error buddy my code is working fentastic all i need to do is dat is there something code like refresh ??? my datas has been deleted but if i want 2 c that new updated table i hav 2 close this form and again open the form ... so my que is is there any code where i can c my datas are updating at runtime... Thanks Hope u understand

  4. #4
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Re: having error at updating database

    hopefully correct what I understand
    add this in your code :
    vb Code:
    1. adapter.Update(DataSet1, "table2")
    2. DataSet1.AcceptChanges()

  5. #5
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: having error at updating database

    what you want to refresh & where do you want to see.
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  6. #6
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 2010
    Location
    MSDN Library
    Posts
    259

    Re: having error at updating database

    Quote Originally Posted by hardygandhi View Post
    I havn't got error buddy my code is working fentastic all i need to do is dat is there something code like refresh ??? my datas has been deleted but if i want 2 c that new updated table i hav 2 close this form and again open the form ... so my que is is there any code where i can c my datas are updating at runtime... Thanks Hope u understand
    yeah thats also my problem in my datagrid..
    i have a form dialogue but when i close the dialogue i cannot see the new data in my datagrid... i also use the datagridview1.refresh but nothing happens..

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Re: having error at updating database

    Quote Originally Posted by Tengkorak View Post
    hopefully correct what I understand
    add this in your code :
    vb Code:
    1. adapter.Update(DataSet1, "table2")
    2. DataSet1.AcceptChanges()
    I tried ur code but nthing happens mens there is no error my data's are deleted but as i said in precious post i hav 2 close the form and again open the form to check the new updated table !!!!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Re: having error at updating database

    Quote Originally Posted by marniel647 View Post
    yeah thats also my problem in my datagrid..
    i have a form dialogue but when i close the dialogue i cannot see the new data in my datagrid... i also use the datagridview1.refresh but nothing happens..
    So buuudy u found error if u find then post it here..How to use refresh command do u know?

  9. #9
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Wink Re: having error at updating database

    ok,ok guys
    let think in other way & what are all needs to be refreshed.

    (1) from where the data is coming
    (2) where it is being shown

    (1) accordingly the data source , i mean the data table which is set as the data source for the Data grid view should be refreshed first with fresh data.
    that means the dataset + its table should be re populated or else we must add the changes to the dataset.

    next

    (2)for a while disconnect the datagrid view from its data source until the changes could take place with in the data source

    (3) now refresh the datagrid view
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  10. #10
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 2010
    Location
    MSDN Library
    Posts
    259

    Re: having error at updating database

    Quote Originally Posted by hardygandhi View Post
    So buuudy u found error if u find then post it here..How to use refresh command do u know?
    i know the refresh command but it is not working..

    this is the refresh command in the datagridview1

    vb.net Code:
    1. datagridview1.refresh

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Re: having error at updating database

    srry bro can u please explain in details bcs i'm in new in this Thanks
    i can understand ur 1st piont bt cant understand 2nd point

  12. #12
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 2010
    Location
    MSDN Library
    Posts
    259

    Re: having error at updating database

    Quote Originally Posted by make me rain View Post
    ok,ok guys
    let think in other way & what are all needs to be refreshed.

    (1) from where the data is coming
    (2) where it is being shown

    (1) accordingly the data source , i mean the data table which is set as the data source for the Data grid view should be refreshed first with fresh data.
    that means the dataset + its table should be re populated or else we must add the changes to the dataset.

    next

    (2)for a while disconnect the datagrid view from its data source until the changes could take place with in the data source

    (3) now refresh the datagrid view
    here is my code to display the data in my datagrid vie the data is coming from a data table..

    rReader is my oledb command
    vb.net Code:
    1. table.Load(rReader)
    2.  
    3.                 DataGridView1.DataSource = table

  13. #13
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: having error at updating database

    Guys please note, i never set the DGV data source so for in any of my applications, but instead i paint the values directly in to the cells, i don't know it's good or bad but it is my habit.
    any how please check this code & reply please
    vb Code:
    1. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    2.  
    3.         Me.DataGridView1.DataSource = Nothing
    4.         Me.DataGridView1.EndEdit()
    5.         Dim connStr As String = "Database=rcd2630su;" & _
    6.                     "Data Source=LocalHost;" & _
    7.                     "User Id=root;Password=~!^%&*((&%$#@#"
    8.  
    9.         Dim connection As New MySqlConnection(connStr)
    10.         connection.Open()
    11.  
    12.         Dim SQL As String = "SELECT * FROM basicCREW"
    13.         Dim CMD As New MySqlCommand(SQL, connection)
    14.         Dim Da As New MySqlDataAdapter(CMD)
    15.         Dim Ds As New DataSet
    16.  
    17.         Da.Fill(Ds, "MyData")
    18.  
    19.         Me.DataGridView1.DataSource = Ds.Tables("MyData")
    20.         Me.DataGridView1.Refresh()
    21.  
    22.     End Sub
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  14. #14
    Junior Member
    Join Date
    Apr 2011
    Location
    India
    Posts
    16

    Re: having error at updating database

    The code seams right. you can make a function fillgrid() and write below code in it
    Code:
            DataGridView1.DataSource = Nothing
    #
            DataGridView1.EndEdit()
    #
            Dim connStr As String = "Database=rcd2630su;" & _
    #
                        "Data Source=LocalHost;" & _
    #
                        "User Id=root;Password=~!^%&*((&%$#@#"
    #
     
    #
            Dim connection As New MySqlConnection(connStr)
    #
            connection.Open()
    #
     
    #
            Dim SQL As String = "SELECT * FROM basicCREW"
    #
            Dim CMD As New MySqlCommand(SQL, connection)
    #
            Dim Da As New MySqlDataAdapter(CMD)
    #
            Dim Ds As New DataSet
    #
     
            Da.Fill(Ds)
    #
            DataGridView1.rows.clear()
    #
            DataGridView1.DataSource = Ds.Tables(0)
    #
    hope it helps u....

  15. #15
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Smile Re: having error at updating database

    Ok guys if you found the solution, i think the thread shall be marked as Resolved
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    25

    Re: having error at updating database

    nah srry its not solved yet

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width