Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 7th, 2006, 10:45 PM   #1
jcrcarmo
Newbie
 
Join Date: Feb 2006
Posts: 11
Rep Power: 0 jcrcarmo is on a distinguished road
Question C# VS 2005 - SQL Query Parameters to an ODBC DataSource

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.
jcrcarmo is offline   Reply With Quote
Old Apr 8th, 2006, 11:55 PM   #2
biran
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 biran is on a distinguished road
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.
biran is offline   Reply With Quote
Old Apr 9th, 2006, 4:08 AM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
@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
nnxion is offline   Reply With Quote
Old Apr 10th, 2006, 3:58 PM   #4
TheCodeLord
Newbie
 
Join Date: Apr 2006
Posts: 7
Rep Power: 0 TheCodeLord is on a distinguished road
Send a message via ICQ to TheCodeLord Send a message via MSN to TheCodeLord Send a message via Yahoo to TheCodeLord
WHERE (Cliente = ?) AND (Data >= ?) AND (Data <= ?) AND (Tipo = ?)

Someone please explain to me this syntax, never seen such a query before
TheCodeLord is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC