14 Replies - 1747 Views - Last Post: 16 April 2011 - 08:49 AM Rate Topic: -----

#1 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

how to update database @ runtime

Posted 08 April 2011 - 02:05 AM

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??
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


Is This A Good Question/Topic? 0
  • +

Replies To: how to update database @ runtime

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 08 April 2011 - 07:03 AM

Where is your update procedure? What does it look like? If you don't have one then there's your problem. The adapters have an "update" object inside of them, but unless it was auto generated code or you specify the sql statement to update it won't do anything!
Was This Post Helpful? 0
  • +
  • -

#3 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 08 April 2011 - 10:28 PM

View Postmodi123_1, on 08 April 2011 - 07:33 PM, said:

Where is your update procedure? What does it look like? If you don't have one then there's your problem. The adapters have an "update" object inside of them, but unless it was auto generated code or you specify the sql statement to update it won't do anything!

I have written it
adapter.Update(DataSet1, "table2")
my problem is when i delete my data it will delete it and my data is updated but to see that updated data i hav to reopen the form!!!!so i want to do like this when i delete data from my datatable i can see that updated table in form without reopening the form Hope u understand
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 09 April 2011 - 09:16 AM

That is not an update procedure, but what ever.

I am not sure what you are getting at, but how about after you 'update' you do a load from the database again? Is that showing your data then?
Was This Post Helpful? 0
  • +
  • -

#5 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 11 April 2011 - 01:29 AM

View Postmodi123_1, on 09 April 2011 - 09:46 PM, said:

That is not an update procedure, but what ever.

I am not sure what you are getting at, but how about after you 'update' you do a load from the database again? Is that showing your data then?

Can u please show me the update procedure???
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 11 April 2011 - 06:47 AM

UPDATES are written like your SELECT or DELETE.

Here's some information.
http://msdn.microsof...=sql.80%29.aspx
Was This Post Helpful? 0
  • +
  • -

#7 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 11 April 2011 - 10:13 PM

View Postmodi123_1, on 11 April 2011 - 07:17 PM, said:

UPDATES are written like your SELECT or DELETE.

Here's some information.
http://msdn.microsof...=sql.80%29.aspx

Thank you !!!!!!!!!! i hav another problem i want 2 select data from data gridview and want retrive that data into another form in to the textbox...is it possible ???? i 'm doing like this for that
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim myConnection As OleDbConnection = New OleDbConnection
        Dim str_oledb_account_select As String = "SELECT * FROM Table3"
        Dim comAccountSelect As OleDbCommand 'command for Account select
        Dim myAccountAdapter As OleDbDataAdapter
        Dim myAccountDataset As DataSet

        Dim textbox2 As TextBox
        Dim i, j As Integer
        Dim vbn As Boolean
        vbn = True
        myConnection.Open()

        'Instantiate the commands
        comAccountSelect = New OleDbCommand(str_oledb_account_select, myConnection)

        'Instantiate data adapter
        myAccountAdapter = New OleDbDataAdapter(str_oledb_account_select, myConnection)
        'Set data adapter command properties
        myAccountAdapter.SelectCommand = comAccountSelect

        'Instantiate the datasets
        myAccountDataset = New DataSet()

        'Populate the dataset
        myAccountAdapter.Fill(myAccountDataset, "Table3")
        j = myAccountDataset.Tables("Table3").Rows.Count()
        For i = 0 To (j - 1)
            TextBox2.Text = myAccountDataset.Tables("Table3").Rows(i)(0)

        Next

     

    End Sub


Please help regarding this !!!!!!!

This post has been edited by hardygandhi: 11 April 2011 - 10:15 PM

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 12 April 2011 - 07:11 AM

i want 2 select data from data gridview 


That's pretty straight forward. There are events for the grid that will help you with that.


and want retrive that data into another form in to the textbox...is it possible ????


You want to take a row of data from the grid and send it to a second form that has a text box? Yes that is possible.

i 'm doing like this for that 

I see you loading up the data, and you looping through a table overwriting a textbox's comment. What I don't see is the second form being declared. I also don't understand why you are looping through a dataset and over writing the contents of a text box. That doesn't make sense.
Was This Post Helpful? 0
  • +
  • -

#9 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 13 April 2011 - 10:30 PM

can u pls show me the right way ????
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 14 April 2011 - 08:09 AM

View Posthardygandhi, on 14 April 2011 - 12:30 AM, said:

can u pls show me the right way ????



Give you the code? No. That's the part where you tackle the problem and gain insight and skills!
Was This Post Helpful? 0
  • +
  • -

#11 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 15 April 2011 - 12:13 AM

View Postmodi123_1, on 14 April 2011 - 08:39 PM, said:

View Posthardygandhi, on 14 April 2011 - 12:30 AM, said:

can u pls show me the right way ????



Give you the code? No. That's the part where you tackle the problem and gain insight and skills!

Bro i'm not asking for the code i say can u please tell me the method !!!!!!!
Was This Post Helpful? 0
  • +
  • -

#12 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 215
  • View blog
  • Posts: 1,408
  • Joined: 16-March 11

Re: how to update database @ runtime

Posted 15 April 2011 - 06:14 AM

Modhi would that be under simple string manipulation?
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 15 April 2011 - 07:29 AM

Okay... there's no singular method. Generally speaking:

User selects row.
user hits button, double clicks, what ever - triggers an event that starts sending data to another form.
Grab the grid's current selected row. Make sure to have multiple select off, or determine how to deal with multiple selected rows.
Grab what ever cell of data from that row.

On form2 have a public string property that links to the textbox's text property.
Create a new instance of form2.
The cell of data mentioned above - assign that to this form2 instance's text property you made.
Show form2
Was This Post Helpful? 0
  • +
  • -

#14 hardygandhi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-March 11

Re: how to update database @ runtime

Posted 15 April 2011 - 10:30 PM

View Postmodi123_1, on 15 April 2011 - 07:59 PM, said:

Okay... there's no singular method. Generally speaking:

User selects row.
user hits button, double clicks, what ever - triggers an event that starts sending data to another form.
Grab the grid's current selected row. Make sure to have multiple select off, or determine how to deal with multiple selected rows.
Grab what ever cell of data from that row.

On form2 have a public string property that links to the textbox's text property.
Create a new instance of form2.
The cell of data mentioned above - assign that to this form2 instance's text property you made.
Show form2

Atleast u shud say dat d code i show u for the retrivig data is near about my work or not?? B)
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6610
  • View blog
  • Posts: 23,941
  • Joined: 12-June 08

Re: how to update database @ runtime

Posted 16 April 2011 - 08:49 AM

I am not sure what you mean, but your code shows you loading data. My steps are what happens *after* you have the data loaded up.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1