473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

having problem in Select statement

in my windows form,for search,two combo boxes are provided.the first one gives the table names and in second combo box the respective fields are provided ,by selecting any field the user enters the required value according to which te search is done

i m storing both tablename and field name in string
now in my select statement when i append the string with field name (with hard coded table name); it functions well but when i concatenate string having table name it gives errors..
Jul 12 '07 #1
3 1195
in my windows form,for search,two combo boxes are provided.the first one gives the table names and in second combo box the respective fields are provided ,by selecting any field the user enters the required value according to which te search is done

i m storing both tablename and field name in string
now in my select statement when i append the string with field name (with hard coded table name); it functions well but when i concatenate string having table name it gives errors..
could you please paste the part of the code?

you need to take care of datatype of the comparing (condition) field

string str = "select * from " + ddltablename + " where "+ ddlfieldname "='" + fieldvalue +"' ";

this one was for varchar type condition variable. where as for numeric type condition value it will be ......ddlfieldname "=" + fieldvalue;
Jul 12 '07 #2
could you please paste the part of the code?

you need to take care of datatype of the comparing (condition) field

string str = "select * from " + ddltablename + " where "+ ddlfieldname "='" + fieldvalue +"' ";

this one was for varchar type condition variable. where as for numeric type condition value it will be ......ddlfieldname "=" + fieldvalue;
if(combobox2.text==" teachers name")
str="t_name"; //giving field name
//many if statements here

strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE tbl1." + str + "=" + textBox1.Text+"AND

tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id ";

it works
but when i do

//tablename=combobox1.text;
//or
tablename="tbl1";

strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id ";

it gives error
Jul 12 '07 #3
if(combobox2.text==" teachers name")
str="t_name"; //giving field name
//many if statements here

strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE tbl1." + str + "=" + textBox1.Text+"AND

tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id ";

it works
but when i do

//tablename=combobox1.text;
//or
tablename="tbl1";

strQuery = " SELECT * FROM tbl1,tbl2,tbl3 WHERE" + tablename + "." + str + "=" + textBox1.Text+"AND tbl1.t_id=tbl2.tb_id AND tbl.t_id=tbl3.tb3_id ";

it gives error
if the above posted query is exact one then it requires a space after where clause, also if you can mind the space given before first "AND".

try if it helps you, or if you can also paste the error.
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
1
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() ...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
5
by: Cirene | last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query with a UNION. But I can't find the example....
7
by: tiptap | last post by:
Hey Guys, I have a huge statement loads of if statements in... and its getting bigger. On closer inspection there is only 3 difference in the select statement. so I thought I could cut the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.