![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Posts: 11
Rep Power: 0
![]() |
Hello everyone,
I used to have my MS Access 2002 DataBase placed in my application folder and connect to it through an OLEDB connection. Everything worked fine. Now I decided to create an ODBC DataSource and suddenly I'm not able to pass parameters to the SQL Query the way I used to with the OLEDB connection. Here's a sample code of the SQL Query and C# code on my form: FillByClienteDataNumero query: SELECT Data, Cliente, Tipo, Número, Espécie, Lote, Análise, Preço FROM qryALL1 WHERE (Cliente = ?) AND (Data >= ?) AND (Data <= ?) AND (Tipo = ?) ORDER BY Data, Número Form code: private void btnSeekBA_Click(object sender, EventArgs e)
{
try
{
this.qryALL1TableAdapter.FillByClienteDataTipo(this.sascrDataSet.qryALL1, cbCliente.Text, new System.Nullable<System.DateTime>(((System.DateTime)(System.Convert.ChangeType(DataIni.Text, typeof(System.DateTime))))), new System.Nullable<System.DateTime>(((System.DateTime)(System.Convert.ChangeType(DataFin.Text, typeof(System.DateTime))))), "Boletim");
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}Any ideas why the above SQL query and code work with an OLEDB connection but not with an ODBC DataSource? Thanks a million! JC. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Apr 2006
Posts: 11
Rep Power: 0
![]() |
HI jcrcarmo,
i am phasing a roblem in OLEDB if you know about my problem please help me about below code.. i have a AccessDatabase and all fields data type are text and i am adding data from C# form window. when i click save button its giving me ERROR IN INSERT INTO STATEMENT. I did like this: private void SaveAndAddnew_Click(object sender, EventArgs e) { try { string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\\reco.mdb"; OleDbConnection myConn = new OleDbConnection(strConn); myConn.Open(); string strInsert = "INSERT INTO Students(ID,Student_Name,Gender,Phone_No,Year,Father_Name)VALUES("+ID.Text+",'" + Student_Name.Text + "','" + Gender.Text + " ',' " + Phone_Number.Text + " ','" + Year.Text + "','" + Father_Name.Text+"')"; OleDbCommand inst = new OleDbCommand(strInsert, myConn); inst.ExecuteNonQuery(); myConn.Close(); } catch (Exception ed) { MessageBox.Show("Error in Saving\n" + ed.ToString(), "Error"); } } But I am getting syntax error at "INSERT INTO STATEMENT Where is the problem please help me tooo. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
@Jcrcarmo: WHERE (Cliente = ?) AND (Data >= ?) AND (Data <= ?) AND (Tipo = ?) will likely be your problem.
@biran: I didn't look at your code, but you should look at the "How to post a question" thread at the top of the C or C++ forum.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#4 |
|
Newbie
|
WHERE (Cliente = ?) AND (Data >= ?) AND (Data <= ?) AND (Tipo = ?)
Someone please explain to me this syntax, never seen such a query before |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|