4
Reply

Please what's wrong here???

Israel

Israel

May 9 2016 7:50 AM
257
Hi!
 Please there's something wrong into this sql query??? I use a MS access data base with a column  "company" as text data type and "year" as text data type. I need to know if there is something wrong wrinting cote.
 
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LunaVisa\Visa\Visa\App_Data\visa.mdb;Persist Security Info=False";
OleDbConnection sqlCon = new OleDbConnection(connectionString);
sqlCon.Open();
string commandString = "select top 1 * from Bill where company ='" + company.Text + "' and year =" + txtYear.Text + " order by billNumber desc"; //the bugs message is : 
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: incorrect expression.
 
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
txtResFactN.Text = read["numfactura"].ToString(); // it will show your friend's name
//txtMention21.Text = read["codempresa"].ToString(); // it will show your friend's name
}
}
else
{
MessageBox.Show("A ultima numeração " + cbxEmpresa.Text + " não foi encontrada");
}
read.Close();
sqlCon.Close();

Answers (4)