EDN Admin
Well-known member
I keep getting the following error :Specified cast is not valid.
I dont understand as to why as all the values Im am getting from a access database are set to text anyway. Here is my code:
<pre class="prettyprint string connString = "Provider=Microsoft.ACE.OleDb.12.0;" + "Data Source=../../Cash.mdb";
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
string nummy = listBox1.SelectedValue.ToString();
OleDbCommand queryStringAll = conn.CreateCommand();
queryStringAll.CommandText = "SELECT Firstname, Surname, Initials, RAddr1, RAddr2, RAddr3, RAddr4, RPostalCode, PAddr1, PAddr2, PAddr3, PAddr4, PPostalCode, HomeNo, FaxNo, CellNo, Email FROM [Client] WHERE (IdNo = " + textBox6.Text.ToString() + ")";
OleDbDataReader read = queryStringAll.ExecuteReader();
while (read.Read())
{
string Firstname = read.GetString(0);
string Surname = read.GetString(1);
string Initials = read.GetString(2);
string RAddr1 = read.GetString(3);
string RAddr2 = read.GetString(4);
string RAddr3 = read.GetString(5);
string RAddr4 = read.GetString(6);
string RPostalCode = read.GetString(7);
string PAddr1 = read.GetString(8);
string PAddr2 = read.GetString(9);
string PAddr3 = read.GetString(10);
string Paddr4 = read.GetString(11);
string PPostalCode = read.GetString(12);
string HomeNo = read.GetString(13);
string WorkNo = read.GetString(14);
string FaxNo = read.GetString(15);
string CellNo = read.GetString(16);
string Email = read.GetString(17);
// string VehicleReg = read.GetString(17);
// string DateOfBirth = read.GetString(18);
// textBox27.Text = Firstname.ToString();
textBox26.Text = Surname.ToString();
textBox25.Text = Initials.ToString();
textBox24.Text = RAddr1.ToString();
textBox23.Text = RAddr2.ToString();
textBox22.Text = RAddr3.ToString();
textBox21.Text = RAddr4.ToString();
textBox20.Text = RPostalCode.ToString();
textBox19.Text = PAddr1.ToString();
textBox18.Text = PAddr2.ToString();
textBox17.Text = PAddr3.ToString();
textBox16.Text = PAddr4.ToString();
textBox15.Text = PPostalCode.ToString();
textBox14.Text = HomeNo.ToString();
textBox13.Text = WorkNo.ToString();
textBox12.Text = FaxNo.ToString();
textBox11.Text = CellNo.ToString();
textBox10.Text = Email.ToString();
}
read.Close();
}[/code]
View the full article
I dont understand as to why as all the values Im am getting from a access database are set to text anyway. Here is my code:
<pre class="prettyprint string connString = "Provider=Microsoft.ACE.OleDb.12.0;" + "Data Source=../../Cash.mdb";
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
string nummy = listBox1.SelectedValue.ToString();
OleDbCommand queryStringAll = conn.CreateCommand();
queryStringAll.CommandText = "SELECT Firstname, Surname, Initials, RAddr1, RAddr2, RAddr3, RAddr4, RPostalCode, PAddr1, PAddr2, PAddr3, PAddr4, PPostalCode, HomeNo, FaxNo, CellNo, Email FROM [Client] WHERE (IdNo = " + textBox6.Text.ToString() + ")";
OleDbDataReader read = queryStringAll.ExecuteReader();
while (read.Read())
{
string Firstname = read.GetString(0);
string Surname = read.GetString(1);
string Initials = read.GetString(2);
string RAddr1 = read.GetString(3);
string RAddr2 = read.GetString(4);
string RAddr3 = read.GetString(5);
string RAddr4 = read.GetString(6);
string RPostalCode = read.GetString(7);
string PAddr1 = read.GetString(8);
string PAddr2 = read.GetString(9);
string PAddr3 = read.GetString(10);
string Paddr4 = read.GetString(11);
string PPostalCode = read.GetString(12);
string HomeNo = read.GetString(13);
string WorkNo = read.GetString(14);
string FaxNo = read.GetString(15);
string CellNo = read.GetString(16);
string Email = read.GetString(17);
// string VehicleReg = read.GetString(17);
// string DateOfBirth = read.GetString(18);
// textBox27.Text = Firstname.ToString();
textBox26.Text = Surname.ToString();
textBox25.Text = Initials.ToString();
textBox24.Text = RAddr1.ToString();
textBox23.Text = RAddr2.ToString();
textBox22.Text = RAddr3.ToString();
textBox21.Text = RAddr4.ToString();
textBox20.Text = RPostalCode.ToString();
textBox19.Text = PAddr1.ToString();
textBox18.Text = PAddr2.ToString();
textBox17.Text = PAddr3.ToString();
textBox16.Text = PAddr4.ToString();
textBox15.Text = PPostalCode.ToString();
textBox14.Text = HomeNo.ToString();
textBox13.Text = WorkNo.ToString();
textBox12.Text = FaxNo.ToString();
textBox11.Text = CellNo.ToString();
textBox10.Text = Email.ToString();
}
read.Close();
}[/code]
View the full article