![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
|
Hi, 1.) I have the following queries in C# code but when I try to run it I get error message saying expecting (;,;, in my querystring theReply = ""; string theReply1 = ""; theReply = reader.ReadString(); theReply1 = reader.ReadString(); IP = theReply; city = theReply1; oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM " + "Customer WHERE IP Address = '"IP"' OR City = '"city"'"; dataSet1.Clear(); oleDbDataAdapter1.Fill(dataSet1, "Customer"); dataGrid1.SetDataBinding(dataSet1,"Customer"); if (dataSet1 == NULL) { textBox.Text += "Hey"; } error message below... : expected :expected ;expected 2.) To check if the queries result in a dataset is empty (that is the queries did not find a match) , can you check it against Null like below... if (dataSet1 == NULL) { textBox.Text += "Hey"; } Your response will be greatly appreciated. Thanks tiger |
#2
| |||
| |||
|
|
First, I use vb.net, but the two are pretty similar so this should work anyway... 1. some suggestions... First, put your SQL into a string variable, then pass the variable as the command text. This makes no difference technically, but makes the code easier to read and simplifies debugging. Second, output the SQL String before you execute it. If you have trouble you can cut and paste the string itself to execute it manually in your database tool. Then you can fix the SQL outside of VisualStudio and seperate SQL errors from C# errors. Soem problems I see... the field name "IP Address" is invalid becuase it contains a space. You may have the wrong field name, or you may need to place [] around the field name in your SQL. you are usign your variables in your SQL without concatenating them. I think this should through an error when compiling. Add in the + for concatenation. Also, although concatenation works for your example, you want to use parameters in place of concatenation or you run into security issues. This is nto really a problem for academic programs, but worht looking into once you get the hang of basic queries. string mySQL ; mySQL = "select * from Customer where [IP Address] = '" + IP + "' OR City = '" + city + "'"; oleDbDataAdapter1.SelectCommand.CommandText = mySQL 2. To check if the dataset is empty try using is nothing (this works in VB, not certain about C#. if (dataSet1 is nothing) |
#3
| |||
| |||
|
|
"Jim Underwood" <james.underwood (AT) fallonclinic (DOT) com> wrote in message news:e8dAri$3FHA.696 (AT) TK2MSFTNGP09 (DOT) phx.gbl... First, I use vb.net, but the two are pretty similar so this should work anyway... 1. some suggestions... First, put your SQL into a string variable, then pass the variable as the command text. This makes no difference technically, but makes the code easier to read and simplifies debugging. Second, output the SQL String before you execute it. If you have trouble you can cut and paste the string itself to execute it manually in your database tool. Then you can fix the SQL outside of VisualStudio and seperate SQL errors from C# errors. Soem problems I see... the field name "IP Address" is invalid becuase it contains a space. You may have the wrong field name, or you may need to place [] around the field name in your SQL. you are usign your variables in your SQL without concatenating them. I think this should through an error when compiling. Add in the + for concatenation. Also, although concatenation works for your example, you want to use parameters in place of concatenation or you run into security issues. This is nto really a problem for academic programs, but worht looking into once you get the hang of basic queries. string mySQL ; mySQL = "select * from Customer where [IP Address] = '" + IP + "' OR City = '" + city + "'"; oleDbDataAdapter1.SelectCommand.CommandText = mySQL 2. To check if the dataset is empty try using is nothing (this works in VB, not certain about C#. if (dataSet1 is nothing) In C#, you need to check each table in the dataset for rows, something like this... if(dataSet11.Tables[0].Rows.Count == 0) { MessageBox.Show("No data"); } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |