Click here to Skip to main content
15,887,027 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: .net framework 2.0.50727 Pin
P P Vilsad11-May-07 20:18
P P Vilsad11-May-07 20:18 
QuestionRe: .net framework 2.0.50727 Pin
Sonia Gupta11-May-07 20:42
Sonia Gupta11-May-07 20:42 
QuestionRe: .net framework 2.0.50727 Pin
Sonia Gupta11-May-07 22:03
Sonia Gupta11-May-07 22:03 
AnswerRe: .net framework 2.0.50727 Pin
P P Vilsad11-May-07 22:26
P P Vilsad11-May-07 22:26 
QuestionRe: .net framework 2.0.50727 Pin
Sonia Gupta11-May-07 23:16
Sonia Gupta11-May-07 23:16 
AnswerRe: .net framework 2.0.50727 Pin
P P Vilsad12-May-07 19:45
P P Vilsad12-May-07 19:45 
Questionsetup exploration [modified] Pin
Sonia Gupta11-May-07 18:26
Sonia Gupta11-May-07 18:26 
QuestionProblem in OleDbDataAdapter.Update [modified] Pin
azusakt11-May-07 17:02
azusakt11-May-07 17:02 
Hi,

I have to do updates to my mdb access database, which has 2 column, user_name and user_pwd.
I have followed the suggestion from MSDN, but I don't know it still got error when excuting update().It says "Update command" or "Insert Command" to have connection object...
Can someone give me some hints or point out to me that What I missed?
Here is my code:

<br />
    Dim connStr As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\me.mdb")<br />
    Dim sqlStr As String = "SELECT * FROM wpLogin"<br />
    Dim dt As New DataTable()<br />
    Dim dataAdapter As OleDbDataAdapter<br />
    Dim ODBconn As OleDbConnection<br />
<br />
<br />
    Public Function CreateDataAdapter(ByVal selectCommand As String, ByVal connection As OleDbConnection) As OleDbDataAdapter<br />
<br />
        <pre>Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(selectCommand, connection)<br />
<br />
        adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey<br />
<br />
        ' Create the commands.<br />
        adapter.InsertCommand = New OleDbCommand( _<br />
            "INSERT INTO wpLogin (user_name, user_pwd) " & _<br />
             "VALUES (?, ?)")<br />
<br />
        adapter.UpdateCommand = New OleDbCommand( _<br />
            "UPDATE wpLogin SET user_name = ?, user_pwd = ? " & _<br />
            "WHERE user_name = ?")<br />
<br />
        adapter.DeleteCommand = New OleDbCommand("DELETE FROM wpLogin WHERE user_name = ?")<br />
<br />
        ' Create the parameters.<br />
        adapter.InsertCommand.Parameters.Add( _<br />
            "@user_name", OleDbType.Char, 50, "user_name")<br />
        adapter.InsertCommand.Parameters.Add( _<br />
            "@user_pwd", OleDbType.Char, 50, "user_pwd")<br />
<br />
        adapter.UpdateCommand.Parameters.Add( _<br />
            "@user_name", OleDbType.Char, 50, "user_name")<br />
        adapter.UpdateCommand.Parameters.Add( _<br />
            "@user_pwd", OleDbType.Char, 50, "user_pwd")<br />
<br />
        adapter.DeleteCommand.Parameters.Add( _<br />
            "@user_name", OleDbType.Char, 50, "user_name").SourceVersion = _<br />
            DataRowVersion.Original<br />
<br />
        Return adapter<br />
    </pre>End Function<br />
<br />
<br />
    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click<br />
        <pre>'Displays the table's data in the data grid<br />
        'Clear the current contents of the table<br />
        dt.Clear()<br />
        'Fill the data table with data from the database<br />
        'Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)<br />
        ODBconn = New OleDbConnection(connStr)<br />
        dataAdapter = CreateDataAdapter(sqlStr, ODBconn)<br />
        dataAdapter.Fill(dt)<br />
        'dataAdapter.Dispose()<br />
        'Display the table in the data grid<br />
        dgDisplay.DataSource = dt</pre><br />
    End Sub<br />
<br />
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click<br />
        'Save the tables's changes back to the database<br />
        <pre>Dim changes As Integer<br />
<br />
<br />
        'Update the database with changes from the data table<br />
        changes = dataAdapter.Update(dt)<br />
        'dataAdapter.Dispose()<br />
        'Display the number of changes made<br />
        If changes > 0 Then<br />
            MsgBox(CStr(changes) & " changed rows were stored in the database.")<br />
        Else<br />
            MsgBox("No changes made.")<br />
        End If</pre>    <br />
End Sub<br />
<br />
    Private Sub UserManager_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing<br />
        <pre>dataAdapter.Dispose()</pre><br />
    End Sub<br />
End Class<br />



-- modified at 23:08 Friday 11th May, 2007
QuestionHow to hide frame when clicking on white area of listview where there is no data? Pin
method00711-May-07 9:56
method00711-May-07 9:56 
Questionmultiple file search Pin
jds120711-May-07 7:05
jds120711-May-07 7:05 
AnswerRe: multiple file search Pin
P P Vilsad11-May-07 9:03
P P Vilsad11-May-07 9:03 
GeneralRe: multiple file search Pin
jds120711-May-07 9:07
jds120711-May-07 9:07 
AnswerRe: multiple file search Pin
P P Vilsad11-May-07 9:30
P P Vilsad11-May-07 9:30 
GeneralRe: multiple file search Pin
jds120711-May-07 9:54
jds120711-May-07 9:54 
GeneralRe: multiple file search Pin
P P Vilsad11-May-07 10:11
P P Vilsad11-May-07 10:11 
GeneralRe: multiple file search Pin
jds120711-May-07 10:26
jds120711-May-07 10:26 
GeneralRe: multiple file search Pin
P P Vilsad11-May-07 10:35
P P Vilsad11-May-07 10:35 
QuestionVB GIS Project Pin
Zigoxo11-May-07 5:43
Zigoxo11-May-07 5:43 
AnswerRe: VB GIS Project Pin
Colin Angus Mackay11-May-07 5:53
Colin Angus Mackay11-May-07 5:53 
Questionregarding datagrid problem in vb.net? Pin
sathyan_829411-May-07 5:18
sathyan_829411-May-07 5:18 
AnswerRe: regarding datagrid problem in vb.net? Pin
Kevin Nicol11-May-07 7:35
Kevin Nicol11-May-07 7:35 
QuestionSetting Permissions for new folders .NET 2.0 Pin
aro198111-May-07 4:35
aro198111-May-07 4:35 
QuestionSAP.net Connector Pin
sunder vel11-May-07 3:38
sunder vel11-May-07 3:38 
AnswerRe: SAP.net Connector Pin
Dave Kreskowiak11-May-07 3:58
mveDave Kreskowiak11-May-07 3:58 
Questioncode for forex exchange using vb.net 2003 Pin
Stormint11-May-07 3:19
Stormint11-May-07 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.