Modifying Data after Find

base836ball

Active member
Joined
May 4, 2005
Messages
31
Programming Experience
1-3
OK my next problem is this. I am using a find feature that when I put in a stock number it goes to the number and brings up the info on it.

This is how I am doing it.

VB.NET:
[size=2]#[/size][size=2][color=#0000ff]Region[/color][/size][size=2] "Finding Stock"

[/size][size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] btnFind_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] btnFind.Click

[/size][size=2][color=#0000ff]If[/color][/size][size=2] txtFind.Text = "" [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]MessageBox.Show("Please enter a valid Stock number", "Stock Entry Error", MessageBoxButtons.OK)

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]strSQL = "SELECT Id, Check#, Hauling, Storage, Additional, Towing, First, [Driver Amount], [Report Date], [Tow Date], [Mainstay Tow], Comments, ID FROM [Primary Table] WHERE Stock ='" & txtFind.Text & "'"

[/size][size=2][color=#0000ff]If[/color][/size][size=2] SqlConnection1.State = [/size][size=2][color=#0000ff]False[/color][/size][size=2] [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]SqlConnection1.Open()

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2]cmd = [/size][size=2][color=#0000ff]New[/color][/size][size=2] SqlClient.SqlCommand(strSQL, SqlConnection1)

objRead = cmd.ExecuteReader

[/size][size=2][color=#0000ff]While[/color][/size][size=2] objRead.Read

txtStock.Text = txtFind.Text

txtId.text = objRead("ID")

[/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Check#")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtCheck.Text = ""

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtCheck.Text = objRead("Check#")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Hauling")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtHaul.Text = 0

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtHaul.Text = objRead("Hauling")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Storage")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtStor.Text = 0

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtStor.Text = objRead("Storage")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Additional")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtAdd.Text = 0

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtAdd.Text = objRead("Additional")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Towing")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtTAmount.Text = 0

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtTAmount.Text = objRead("Towing")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("First")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]cboTower.Text = "System"

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]cboTower.Text = objRead("First")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Driver Amount")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtDAmount.Text = 0

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtDAmount.Text = objRead("Driver Amount")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Report Date")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]dtpReport.Value = [/size][size=2][color=#0000ff]Date[/color][/size][size=2].Today

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]dtpReport.Value = objRead("Report Date")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Tow Date")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]dtpTow.Value = [/size][size=2][color=#0000ff]Date[/color][/size][size=2].Today

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]dtpTow.Value = objRead("Tow Date")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Mainstay Tow")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]chbMain.Text = ""

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]chbMain.Text = objRead("Mainstay Tow")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2][/size][size=2][color=#0000ff]If[/color][/size][size=2] IsDBNull(objRead("Comments")) [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]txtComment.Text = ""

[/size][size=2][color=#0000ff]Else

[/color][/size][size=2]txtComment.Text = objRead("Comments")

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2]InitialLoad()

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]While

[/color][/size][size=2]objRead.Close()

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If

[/color][/size][size=2]txtFind.Text = ""

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size][size=2]#[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Region

[/color][/size]
Now that works just fine to find a stock and it goes to the right stock number with the corresponding info. If I want to modify some of the info like txtHaul then save it to the DB it still thinks it is in the first position in DB. so say I have ID(PK) 1 and 2 where 1 has stock of 1234 and 2 has stock of 6789. When I load my form stock 1 is shown automatically. When I use the Find feature and put in 6789 and modify the data, I hit the save button(endthecurrentedit and updates DB) it fills in 1234 into the text boxes and never saves to the DB. any clue

Here is my Save button
VB.NET:
[size=2]DsAdd2.Primary_Table.IDColumn.ReadOnly = [/size][size=2][color=#0000ff]False

[/color][/size][size=2]bmbAdd.EndCurrentEdit()

daAdd.Update(DsAdd2.Primary_Table)

DsAdd2.Primary_Table.IDColumn.ReadOnly = [/size][size=2][color=#0000ff]True

[/color][/size]

Thanks
 
See this thread: DataSet or DataReader class
I should also add, if you decide that a dataSet is the best solution (as it seems you are using a dataSet already looking at your save code): to do a search similar to the one you've shown, you can use a dataview, setting the RowFilter property to a valid SQL WHERE clause.
 
Back
Top