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();

Shakti Singh DulawatRank #668 · 3.6K reputationPosted May 9, 2016, 4:37 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted May 9, 2016, 1:43 PM EDT
ali tuncerRank #1,499 · 1.1K reputationPosted May 9, 2016, 8:41 PM EDT
If year is a text column, you will need single quote, like you did for company columm..
Shakti Singh DulawatRank #668 · 3.6K reputationPosted May 10, 2016, 1:28 AM EDT