trend Posted April 13, 2005 Posted April 13, 2005 (edited) 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: ---edit---- what am I doing wrong? I get no errors.. and the db isn't updated. Sorry for the dumb question.. but I have searched and search.. without an answer :/ /edit/ here is the answer: 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() Edited April 13, 2005 by trend Quote
mike55 Posted April 13, 2005 Posted April 13, 2005 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: ---edit---- what am I doing wrong? I get no errors.. and the db isn't updated. Sorry for the dumb question.. but I have searched and search.. without an answer :/ /edit/ here is the answer: 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: 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 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.