I give up... How do you update a row in a db?

trend

Well-known member
Joined
Oct 12, 2004
Messages
171
I have been trying to select one row from a db, then change a field in it.. and update the row in the db.

Here is my code:

Code:
 ---edit----

what am I doing wrong? I get no errors.. and the db isnt updated.

Sorry for the dumb question.. but I have searched and search.. without an answer :/


/edit/

here is the answer:

Code:
        Dim RefID As Integer = DirectCast(sender.Tag, String).ToString
        Dim LookupAvail As String = DirectCast(sender.Text, String).ToString
        Dim Avail() As String = LookupAvail.ToString.Split(" ")
        Dim conn As OleDbConnection
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb;User Id=admin;Password=;"
        conn = New OleDbConnection(connString)

        conn.Open()
        Dim MyCommand As New OleDbCommand("UPDATE x SET y = " & Avail(7) + 1 & " Where z = " & v & "", conn)
        MyCommand.ExecuteNonQuery()
        conn.Close()

        MyCommand.Dispose()
 
Last edited by a moderator:
trend said:
I have been trying to select one row from a db, then change a field in it.. and update the row in the db.

Here is my code:

Code:
 ---edit----

what am I doing wrong? I get no errors.. and the db isnt updated.

Sorry for the dumb question.. but I have searched and search.. without an answer :/



/edit/

here is the answer:

Code:
        Dim RefID As Integer = DirectCast(sender.Tag, String).ToString
        Dim LookupAvail As String = DirectCast(sender.Text, String).ToString
        Dim Avail() As String = LookupAvail.ToString.Split(" ")
        Dim conn As OleDbConnection
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb;User Id=admin;Password=;"
        conn = New OleDbConnection(connString)

        conn.Open()
        Dim MyCommand As New OleDbCommand("UPDATE x SET y = " & Avail(7) + 1 & " Where z = " & v & "", conn)
        MyCommand.ExecuteNonQuery()
        conn.Close()

        MyCommand.Dispose()



Hey

Take a look at this code:

Code:
   Friend WithEvents daDataAdapter As New SqlDataAdapter
    Dim dsDataSet As New DataSet

Dim cnConn As SqlConnection
        Dim value As String
        cnConn = New SqlConnection(clsConnection.osqlStr)
        cnConn.Open()
        daDataAdapter.SelectCommand = New SqlCommand
        daDataAdapter.SelectCommand.Connection = cnConn
        daDataAdapter.SelectCommand.CommandText = procedure
        daDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

        If access = 1 Then
            daDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@OrgID", SqlDbType.NVarChar, 254))
            value = orgID
        Else
            daDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@OrgID", SqlDbType.Int))
            value = Convert.ToInt16(value)
            value = gHeader
        End If
        daDataAdapter.SelectCommand.Parameters("@OrgID").Direction = ParameterDirection.Input
        daDataAdapter.SelectCommand.Parameters("@OrgID").Value = value


       Creates the insert command 
        If iLoop = 0 Then
            daDataAdapter.InsertCommand = New SqlCommand("Insert Into GroupMembership (Member_ID, Group_ID, Org_ID) VALUES (@iMID, @iGID,@iOID)", cnConn)
            daDataAdapter.DeleteCommand = New SqlCommand("Delete from GroupMembership WHERE Member_ID = @dMID and Group_ID = @dGID and Group_ID <> 0", cnConn)
        Else

     End If

        Fill the dataset
        daDataAdapter.Fill(dsDataSet, table)

        cnConn.Close()
        Creates and asign parameters to the insert command
        Parameters: @MID = Member_ID, @oID = Org_ID and @GID = Group_ID
        If iLoop = 0 Then
            daDataAdapter.InsertCommand.Parameters.Add(New SqlParameter("@iMID", SqlDbType.Int))
            daDataAdapter.InsertCommand.Parameters("@iMID").Direction = ParameterDirection.Input
            daDataAdapter.InsertCommand.Parameters("@iMID").SourceColumn = "Member_ID"
            daDataAdapter.InsertCommand.Parameters("@iMID").SourceVersion = DataRowVersion.Current
            daDataAdapter.InsertCommand.Parameters.Add(New SqlParameter("@iGID", SqlDbType.Int))
            daDataAdapter.InsertCommand.Parameters("@iGID").Direction = ParameterDirection.Input
            daDataAdapter.InsertCommand.Parameters("@iGID").SourceColumn = "Group_ID"
            daDataAdapter.InsertCommand.Parameters("@iGID").SourceVersion = DataRowVersion.Current
            daDataAdapter.InsertCommand.Parameters.Add(New SqlParameter("@iOID", SqlDbType.NVarChar, 254))
            daDataAdapter.InsertCommand.Parameters("@iOID").Direction = ParameterDirection.Input
            daDataAdapter.InsertCommand.Parameters("@iOID").SourceColumn = "Org_ID"
            daDataAdapter.InsertCommand.Parameters("@iOID").SourceVersion = DataRowVersion.Current

            daDataAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@dMID", SqlDbType.Int))
            daDataAdapter.DeleteCommand.Parameters("@dMID").Direction = ParameterDirection.Input
            daDataAdapter.DeleteCommand.Parameters("@dMID").SourceColumn = "Member_ID"
            daDataAdapter.DeleteCommand.Parameters("@dMID").SourceVersion = DataRowVersion.Current
            daDataAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@dGID", SqlDbType.Int))
            daDataAdapter.DeleteCommand.Parameters("@dGID").Direction = ParameterDirection.Input
            daDataAdapter.DeleteCommand.Parameters("@dGID").SourceColumn = "Group_ID"
            daDataAdapter.DeleteCommand.Parameters("@dGID").SourceVersion = DataRowVersion.Current
        End If

Mike55
 
Back
Top