?
Solved

Insert a row using code from vb page

Posted on 2005-05-09
10
Medium Priority
?
207 Views
Last Modified: 2010-04-23
How do I update a table from a vb page, below is the code I have started but to tell the truth I'm not really sure what I am writing.

Thanks    


Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click
        ' Display message box to user to confirm deletion
        Dim userid
        userid = TextBox12.Text
        intReturnValue = MsgBox("Are you sure you wish to delete Patient " + userid + "?", MsgBoxStyle.YesNo)
        If (intReturnValue = MsgBoxResult.Yes) Then
            ' If answer = yes then move patient to tblArchive
            Dim dataset1 As New DataSet

            Dim ConnectionString As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial " & _
            "Catalog=healthdistrict;Packet Size=4096;Workstation ID=JCleary;Use Encryption for Data=False"
            Dim Connection1 As OleDbConnection = New OleDbConnection(ConnectionString)

            Dim query As String = _
                 "Insert into tblArchive from tblPatient where lngpatientid = " + userid  

        End If
        'Deletes patient from table duplicates
        'DataSet21.Tables(0).Rows(rowNo).Delete()
        'SqlDataAdapter2.Update(DataSet21)
    End Sub
0
Comment
Question by:running32
  • 5
  • 5
10 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13959929
Do you want to delete or insert

the button says delete but your query says insert
0
 

Author Comment

by:running32
ID: 13959955
I need to insert.  The button says delete because that is what the user thinks they are doing.  But I am moving it to an archived table.

Thanks
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 2000 total points
ID: 13960155
First if you use sqlserver use the sqlclient instead of oledb,

Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click
        ' Display message box to user to confirm deletion
        Dim userid as string
        userid = TextBox12.Text
        intReturnValue = MsgBox("Are you sure you wish to delete Patient " + userid + "?", MsgBoxStyle.YesNo)
        If (intReturnValue = MsgBoxResult.Yes) Then

            Dim Connection1 As new sqlclient.sqlconnection("workstation id=JCleary;packet size=4096;integrated security=SSPI;data source=JCleary;persist security info=False;initial catalog=healthdistrict)

        Dim cmd As New OleDb.OleDbCommand("Insert into tblArchive from tblPatient where lngpatientid = " & userid,Connection1)
        connection1.open  
        cmd.ExecuteNonQuery()
        connection1.close

        End If
        'Deletes patient from table duplicates
        'DataSet21.Tables(0).Rows(rowNo).Delete()
        'SqlDataAdapter2.Update(DataSet21)
    End Sub

(you still have to delete the record from the dataset though)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13960171
sorry this should also be

Dim cmd As New OleDb.OleDbCommand("Insert into tblArchive from tblPatient where lngpatientid = " & userid,Connection1)

this

Dim cmd As New sqlclinet.SqlDbCommand("Insert into tblArchive from tblPatient where lngpatientid = " & userid,Connection1)
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13960200
and I think your query should be changed to this

"Insert into tblArchive select * from tblPatient where lngpatientid = " & userid

although I'm not sure, my sql is a bit rusty these days

0
 

Author Comment

by:running32
ID: 13960250
Thanks for answering back so quickly.

The problem states connection1.open   not declared and sqlclinet.SqlDbCommand
not defined.
0
 

Author Comment

by:running32
ID: 13960302
after adding a " it still comes up with the error SqlClient.SqlDbCommand  not defined.

thanks
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13960305
sorry typo,

it should sqlclient.sqlcommand
0
 

Author Comment

by:running32
ID: 13960495
Thanks for helping.

When I try and run this the program breaks on cmd.ExecuteNonQuery()
0
 

Author Comment

by:running32
ID: 13960939
Thanks that got me started
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question