从SQLite数据库中选择并将其分配给变量

时间:2009-12-21 23:21:13

标签: vb.net sqlite

我正在尝试从SQLite数据库中检索密码。密码所在行的ID是1.我想将他的密码分配给名为actualpass的变量。

这是我在被困之前得到的。有人可以帮忙吗?

Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
    Dim SQConnect As New SQLite.SQLiteConnection
    Dim SQCommand As New SQLite.SQLiteCommand
    Dim actualpass As String
    Dim givenname As String
    Dim path As String
    path = AppDomain.CurrentDomain.BaseDirectory()
    givenname = txtUsername.Text

    SQConnect.ConnectionString = ("Data Source=" & path & "app_data\data.db3")
    SQConnect.Open()
    SQCommand = SQConnect.CreateCommand
    SQCommand.CommandText = ("SELECT password from login_data WHERE id =1")




End Sub

1 个答案:

答案 0 :(得分:1)

DataReader reader = SqCommand.ExecuteReader();

while (reader.Read()) {
   if (reader["password"] != System.DBNull) {
      actualpass = reader["password"] as string;
   } else {
      actualpass = null;
   }

   break; //only want one row and one field
}

应该关闭,从不使用SQLite,我没有IDEA来仔细检查语法。