Failed to convert from a string to a int32
i got a problem where i only be able to retrieve the data from the
database on a single textbox. What i want is, i want to retrieve the data
of every textboxes from the database, but when i tried, getting error:
Here is the code:
string connectionString =
(@"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=\Archives\Projects\Program\Sell System\Sell
System\App_Data\db1.accdb;Persist Security Info=False;");
private List<List<TextBox>> textBoxCodeContainer = new
List<List<TextBox>>();
private List<List<TextBox>> textBoxQuantityContainer = new
List<List<TextBox>>();
private List<List<TextBox>> textBoxDescContainer = new
List<List<TextBox>>();
private List<List<TextBox>> textBoxSubTotalContainer = new
List<List<TextBox>>();
private List<List<TextBox>> textBoxTotalContainer = new
List<List<TextBox>>();
private void Form1_Load(object sender, EventArgs e)
{
UpdateTextPosition();
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT [Code] FROM
[Data]", conn);
dReader = cmd.ExecuteReader();
AutoCompleteStringCollection codesCollection = new
AutoCompleteStringCollection();
while (dReader.Read())
{
string numString = dReader[0].ToString().PadLeft(4, '0');
codesCollection.Add(numString);
}
dReader.Close();
conn.Close();
}
private void UpdateDatas()
{
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT DISTINCT
[Description], [Price] FROM [Data] WHERE [Code]=@Code",
conn);
cmd.Parameters.Add("Code",
System.Data.OleDb.OleDbType.Integer);
cmd.Parameters["Code"].Value =
this.textBoxCodeContainer[0][0].Text;
dReader = cmd.ExecuteReader();
while (dReader.Read())
{
this.textBoxDescContainer[0][0].Text =
dReader["Description"].ToString();
this.textBoxSubTotalContainer[0][0].Text =
dReader["Price"].ToString();
}
dReader.Close();
conn.Close();
}
I already tried add:
cmd.Parameters.Add("Code", System.Data.OleDb.OleDbType.Integer);
cmd.Parameters["Code"].Value =
this.textBoxCodeContainer[0][1].Text;
and
while (dReader.Read())
{
this.textBoxDescContainer[0][1].Text =
dReader["Description"].ToString();
this.textBoxSubTotalContainer[0][1].Text =
dReader["Price"].ToString();
}
but i got an error which says: "Failed to convert parameter value from a
string to a int32"
No comments:
Post a Comment