hey everyone im sort off new on .net and i was wondering if u can help me bigtime.. i am having problems with editing records when i do a search. example i was to search a specific record but then when i try to edit it, it turned out that i am editing the wrong record. but i can update records if i didnt search it.

here is my code for searching:

Private Sub search()
Dim str As String
str = "select * from user_t where Username like ('" & Trim(txtSearch.Text) & "%')"
Try
con.Open()
Dim com1 As New SqlClient.SqlCommand(str, con)
Dim dr As SqlClient.SqlDataReader = com1.ExecuteReader

While dr.Read
txtUsername.Text = "" & (dr.GetValue(0))
txtPassword.Text = "" & (dr.GetValue(1))
cbUsertype.Text = "" & (dr.GetValue(2))

End While
If Not dr.HasRows Then
MsgBox("No records found. Please try again.", MessageBoxIcon.Error, "No records found")
txtSearch.Clear()
End If
con.Close()
Catch ex As Exception
con.Close()
End Try
End Sub


and for updating:

Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
ds.Tables("user_t").Rows(inc).Item("Username") = txtUsername.Text
ds.Tables("user_t").Rows(inc).Item("Password") = txtPassword.Text
MsgBox("User Updated", MsgBoxStyle.Information, "Update Successful")
da.Update(ds, "user_t")

i really need ur help guys..hehe

You using a DataReader in this coding; hence you can only read the values not write back to the database.... You need to spend some time looking through some tutorials about working with datasets

hi tom thanks, are there any sites that can tutor me on working with datasets?

It's a MSDN online page - ADO.NET.

SUMMARY:
ADO.NET is a data-access technology that enables applications to connect to data stores and manipulate data contained in them in various ways. It is based on the .NET Framework and it is highly integrated with the rest of the Framework class library. The ADO.NET API is designed so it can be used from all programming languages that target the .NET Framework, such as Visual Basic, C#, J# and Visual C++.

hi tom thanks, are there any sites that can tutor me on working with datasets?

Yes there are many resources & examples available on the internet. If I can recommend one particular book that will fully explain the many different ways of programming with VB & databases it would be Pro ADO.NET 2.0 I think there may be a downloadable version of this book available too if you search for it.

hey everyone, tnx for helping me out... i already finished ds tnx to ur help guys..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.