1
如何將查詢結果分配給變量。如何爲查詢結果分配變量
我正在使用SQLlite。以下是從用戶表中檢索密碼的代碼。我需要比較給定的密碼和給定的密碼。
Dim i As String
Dim p As String
i = txtUserID.Text
p = txtPassword.Text
Try
Dim sqlConnection As New SQLite.SQLiteConnection()
Dim sqlCommand As New SQLiteCommand("", sqlConnection)
Dim sqlPath As String = "Data Source=" & Application.StartupPath & "\Database\SimpleDB.db3"
Dim sqlQuery As String = "SELECT Password FROM User WHERE UserID LIKE '" & i & "'"
sqlConnection.ConnectionString = sqlPath
sqlConnection.Open()
sqlCommand.CommandText = sqlQuery
sqlCommand.ExecuteNonQuery()
sqlConnection.Close()
Catch ex As Exception
MsgBox("Invalid ID or Password. Please try again.")
End Try
編輯1:
在這下面的代碼爲什麼我需要使用GetInt16(0)。爲什麼16和爲什麼0在參數中。是什麼)GetInt32等(),GetInt16()和GetString(區別所有的
DbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id= reader.GetInt16(0);
}
reader.Close();
先生,您能否向我提供DataReader示例代碼 – 2011-04-24 05:57:48
@Failed_Noob - 先生,您如何遵循我提供的鏈接,閱讀文檔(有示例),並自己學習? – Oded 2011-04-24 05:58:48
對不起,沒有看到鏈接 – 2011-04-24 06:04:33