Vb.net & SQLite
-
Hi, I'm trying to design a login script using VB.net 2008 and the System.Data.SQLite wrapper. So far I have my SQLite tables setup with a default user (user: admin pass: test dob: 1990/01/01 name: John Smith) and I connect using the following code:
Imports System.Data.SQLite
Dim userName As String
Dim passWord As String
userName = usrBox.Text
passWord = passBox.TextDim sqlConnection As New SQLite.SQLiteConnection()
Dim sqlCommand As New SQLiteCommand
sqlConnection.ConnectionString = "Data Source=users.db3
sqlConnection.Open()
sqlCommand = sqlConnection.CreateCommand()
sqlCommand.CommandText = "SELECT * FROM users WHERE username = " & userNameHowever, I don't know how to check if the statement has rows for me to check if the user exists, and then I would have to do the same for passwords. Anyone know how to check if the statement has rows using a similar function? Cheers, Ben.
-
Hi, I'm trying to design a login script using VB.net 2008 and the System.Data.SQLite wrapper. So far I have my SQLite tables setup with a default user (user: admin pass: test dob: 1990/01/01 name: John Smith) and I connect using the following code:
Imports System.Data.SQLite
Dim userName As String
Dim passWord As String
userName = usrBox.Text
passWord = passBox.TextDim sqlConnection As New SQLite.SQLiteConnection()
Dim sqlCommand As New SQLiteCommand
sqlConnection.ConnectionString = "Data Source=users.db3
sqlConnection.Open()
sqlCommand = sqlConnection.CreateCommand()
sqlCommand.CommandText = "SELECT * FROM users WHERE username = " & userNameHowever, I don't know how to check if the statement has rows for me to check if the user exists, and then I would have to do the same for passwords. Anyone know how to check if the statement has rows using a similar function? Cheers, Ben.
You could use a "SELECT COUNT(*) ..." as SQL and then add something like this to your code:
Integer.Parse(sqlCommand.ExecuteScalar().ToString)
Another method is to create a DataTable first (using your SQL statement above):Dim aDataTable As DataTable Dim aDbDataAdapter As DbDataAdapter sqlCommand.CommandText = sql aDbDataAdapter.SelectCommand = sqlCommand aDbDataAdapter.Fill(aDataTable) aDbDataAdapter.FillSchema(aDataTable, SchemaType.Source) aDataTable.TableName = tableName
and then evaluate the Row-Count:aDataTable.Rows.Count