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
Re: having error at updating database
to determine whether the data has been deleted, use:
vb Code:
cmdDelete.CommandText = "DELETE FROM Table2 WHERE ID = " & cint( TextBox1.Text )
Dim iRs As Integer = cmdDelete.ExecuteNonQuery()
if iRs > 0 then
MessageBox.Show(" Records Deleted!! ")
end if
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 :):)
Re: having error at updating database
hopefully correct what I understand
add this in your code :
vb Code:
adapter.Update(DataSet1, "table2")
DataSet1.AcceptChanges()
Re: having error at updating database
what you want to refresh & where do you want to see.
Re: having error at updating database
Quote:
Originally Posted by
hardygandhi
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..
Re: having error at updating database
Quote:
Originally Posted by
Tengkorak
hopefully correct what I understand
add this in your code :
vb Code:
adapter.Update(DataSet1, "table2")
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 !!!!
Re: having error at updating database
Quote:
Originally Posted by
marniel647
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?
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
Re: having error at updating database
Quote:
Originally Posted by
hardygandhi
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
Re: having error at updating database
srry bro can u please explain in details bcs i'm in new in this :D Thanks
i can understand ur 1st piont bt cant understand 2nd point
Re: having error at updating database
Quote:
Originally Posted by
make me rain
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:
table.Load(rReader)
DataGridView1.DataSource = table
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:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Me.DataGridView1.DataSource = Nothing
Me.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, "MyData")
Me.DataGridView1.DataSource = Ds.Tables("MyData")
Me.DataGridView1.Refresh()
End Sub
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....
Re: having error at updating database
Ok guys if you found the solution, i think the thread shall be marked as Resolved :)
Re: having error at updating database
nah srry its not solved yet