Click to See Complete Forum and Search --> : Retriving and Comparing Data


alexandar
August 9th, 2002, 10:51 PM
Hi! I have a question regarding Database. In my form I have a Username Textbox...it is named usertext.text. When the user types in his/her username, I want the programme to checked it with the database that I prepared earlier. How do I do that? The commands seems to be different from VB6.
Thanks....

jayson_13
August 12th, 2002, 05:23 AM
noting much different..

if rs.field("USERNAME").value = txtusername.text then
....
end if
hope helps..

alexandar
August 13th, 2002, 01:59 AM
How do you declare the rs and the database? Do i import the ADODB? How do I open recordset and etc? Thanks...

alexandar
August 14th, 2002, 04:26 AM
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim strSQL As String
Dim strConn As String

Dim rs As New Recordset()


strConn = "Initial Catalog=MatrixVB;Data Source=(local);" _
& "User ID=sa;password=;"
strSQL = "SELECT Super_ID from Supervisor"




If rs.Fields("Super_ID").Value = TextBox1.Text Then

MsgBox("VB.NET!!!")
Else
MsgBox("haha!!")

End If


End Sub

alexandar
August 14th, 2002, 04:28 AM
is there anything wrong with the above coding?

Akim
August 14th, 2002, 03:37 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/adonetprogmsdn.asp

jayson_13
August 15th, 2002, 05:15 AM
u have to add the reference first.
go to project - > add reference -> choose adodb and add it to your project.

after that
dim conn as adodb.connection
dim rs as adodb.recordset
conn = New ADODB.Connection()
rs = New ADODB.Recordset()
sql = "SELECT * FROM USRPWDRECM WHERE REC_USRID = '" & Trim(txtUsrID.Text) & "';"
On Error GoTo ErrConn
conn.Open("Provider=MySQLProv; Data Source=design;server=192.168.100.5; DB=designdept;")
rs = conn.Execute(sql)

above is the coding i do in my project..
hope it helps..
and tomolo is my deadline... :(

alexandar
August 15th, 2002, 08:35 PM
Hi!

Thank you for your reply but I am still getting the below error. WHat is wrong? I am very clueless now. :(

'System.Runtime.InteropServices.COMException

alexandar
August 15th, 2002, 08:36 PM
Is it rs.field or rs.fields?

alexandar
August 15th, 2002, 09:01 PM
what is the Provider? I keep getting the error that says Provider cannot be found......:(

alexandar
August 15th, 2002, 09:35 PM
Akim, I think the MSDN that you recommended is only for retrieving the data.....how do I compare the data after I retrieve it? Thanks

Akim
August 15th, 2002, 11:32 PM
Originally posted by alexandar
Akim, I think the MSDN that you recommended is only for retrieving the data.....how do I compare the data after I retrieve it? Thanks
Compare with what?
Just like you do in VB 6.
Comparison operators are the same (still) .

alexandar
August 15th, 2002, 11:59 PM
Sorry Akim, what do you mean? I am new in VB. Do you have any sample codes?

jayson_13
August 16th, 2002, 06:52 AM
is rs.fields
what database u r using?
mySQL, mSQL, Oracle, Access?
have u configured ur ODBC data source?

configure ur ODBC data source before u start running the code. check it out urself . very easy stuff..

Akim
August 16th, 2002, 08:49 AM
Check out this thread: http://www.codeguru.com/forum/showthread.php?s=&threadid=203140

Download a simple application that's posted there (.zip). You'll find some code samples on how to use dataadapters and datasets.
As for your code... It should look something like that:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim strSQL As String
Dim strConn As String
Dim iInd as Integer
Dim ds As DataSet
Dim da As SqlDataAdapter



strConn = "Initial Catalog=MatrixVB;Data Source=(local);" _
& "User ID=sa;password=;"
strSQL = "SELECT Super_ID from Supervisor"

Dim cn As SqlConnection = New SqlConnection(strConn )
ds = New DataSet()
da = New SqlDataAdapter(strSQL , cn )
da.Fill(ds, "YourTableName")

For iInd = 0 to ds.Tables("YourTableName").Rows.Count-1
If ds.Tables("YourTableName").Rows(iInd).Item("Super_ID")=TextBox1.Text Then

MsgBox("VB.NET!!!")
Else
MsgBox("haha!!")

End If
Next

End Sub


I hope that's what you need.

P.S. There may be "typos" in the code, because I haven't tested it.
Also, you have to:
Imports System.Data.SqlClient

alexandar
August 18th, 2002, 08:20 PM
Thanks Akim! Really appreciate your help.