-1

このコードを VB.NET に変更するにはどうすればよいですか? DataSetだから私は の代わりにADODB.Recordsetと のOleDb.OleDbConnection代わりにを使いたいADODB.Connection

Set oRs = New ADODB.Recordset
  oRs.Open ("Select * from Login Where Username= '" & txtUsername.Text & "'"),oCn,      adOpenStatic, adLockOptimistic, _
 adCmdText

If txtPassword.Text <> oRs.Fields("Password") Then
Call MsgBox("Incorrect Password", vbOKOnly, "Login Error")
txtPassword.Text = ""
txtPassword.SetFocus
Exit Sub
Else

strUserName = txtUsername.Text 'May need in the future project
 strName = oRs.Fields("FirstName") & " " & oRs.Fields("LastName")
 frmInstruction.Show

これは私がこれまでに試したことです:

Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Login WHERE  Username= '" & txtUsername.Text & "' AND password = '" & txtPassword.Text & "' ", oCn)

Dim sdr As OleDbDataReader = cmd.ExecuteReader()

If (sdr.Read() = True) Then

strUserName = txtUsername.Text

frmInstruction.Show()

'but am having issue with this line of code: 
strName = oRs.Fields("FirstName") & " " & oRs.Fields("LastName")
4

1 に答える 1

0

'しかし、このコード行に問題があります:strName = oRs.Fields( "FirstName")& ""&oRs.Fields( "LastName")

OledbDataReader.GetStringFirstNameフィールドとLastNameフィールドを読み取るために使用できます。

Dim firstName = sdr.GetString(sdr.GetOrdinal("FirstName"))
Dim lastName = sdr.GetString(sdr.GetOrdinal("LastName")) 
strName = firstName & " " & lastName 
于 2012-07-11T08:50:12.783 に答える