Reputation:
I'm working on a WPF application and i cant seem to get this right. I am brand new to WPF.
I want to get the text from the database into text boxes but i tried it with only one textbox the first time and i get this error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: No value given for one or more required parameters.
This is the code i have so far, this is how it's done in winforms but i suppose not the same in WPF
dbconn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ChampInfo1.accdb");
dbconn.Open();
string selectallSQL = "SELECT Passive " +
"FROM BChampInfo " +
"WHERE [Champ Name] = Aatrox";
dbcomm = new OleDbCommand(selectallSQL, dbconn);
OleDbDataReader dbread = dbcomm.ExecuteReader();
while (dbread.Read())
{
txtskillname1.Text = dbread["Passive"].ToString();
}
I don't know what is wrong though, any help will be appreciated. All my oledb declaration are done at the top.
Upvotes: 1
Views: 170
Reputation: 12315
It can be the easy target for sql injection. The problem is in query. Try this
string selectallSQL = "SELECT Passive " +
"FROM BChampInfo " +
"WHERE [Champ Name] = ?";
dbcomm = new OleDbCommand(selectallSQL, dbconn);
dbcomm.Parameters.AddWithValue("@aat", "Aatrox");
Upvotes: 1