0
我剛剛切換到使用mysql查詢參數,並擔心我找不到如何將結果保存到數據表中。我想將此選擇查詢的結果保存到數據表「表」中。以前我會做將mysql結果保存到數據表
adptr = New MySqlDataAdapter("SELECT * from users WHERE uname='" & MySqlHelper.EscapeString(UsernameTextBox.Text) & "' and pword=md5('" & MySqlHelper.EscapeString(PasswordTextBox.Text) & "')", con)
Try
adptr.Fill(table)
Catch err As Exception
Dim strError As String = "Exception: & err.ToString()"
End Try
現在我有
Public table As New DataTable
Dim cb As New MySqlConnectionStringBuilder
cb.Database = dbfile
cb.Server = dbserver
cb.UserID = dbuser
cb.Password = dbpassw
Using cnn As New MySqlConnection(cb.ConnectionString)
Using cmd As New MySqlCommand("SELECT * from users WHERE uname=&uname and pword=md5(&pword)", cnn)
cmd.Parameters.AddWithValue("@uname", UsernameTextBox.Text)
cmd.Parameters.AddWithValue("@pword", PasswordTextBox.Text)
Try
cnn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Using
End Using
我怎麼將結果保存到表?
如果使用&uname參數也必須更改 - @也可以工作,雖然 - 謝謝你的答案 –