I can't figure out what's wrong or what the solution might me with my code it just gives me that it can't convert from string to int when i'm not using any ints only strings I also can't figure out how to write and get the datetime to be placed back into the datetimepicker.
private void cbxProducts_SelectedIndexChanged(object sender, EventArgs e)
{
string constring = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\hannes.corbett\\Desktop\\Barcode Scanning\\Barcode Scanning\\BarcodeDB.mdf\"; Integrated Security = True";
string Query = "SELECT * FROM Products where Name='" + cbxProducts.Text + "' ; ";
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
string sBarcode = myReader.GetString("Barcodes");
string sName = myReader.GetString("Name");
var sDate = myReader.GetDateTime("EDate");
string sQuantity = myReader.GetInt32("Quantity")).ToString();
string sPrice = myReader.GetInt32("Price")).ToString();
tbxBar.Text = sBarcode;
tbxName.Text = sName;
sDate = dateDate.Value;
tbxPrice.Text = sPrice;
tbxQua.Text = sQuantity;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
EDIT: Error Message
EDIT 2: I get the error message
"An invalid attempt was made to read when no data was available"
I have data in all of the strings in my database but i still get this error