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..
$h@ma!|@
say me your error to check it.
We Can Do Anything, If We Want It
-
say me your error to check it.
We Can Do Anything, If We Want It
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
$h@ma!|@
-
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
$h@ma!|@
what error?
Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus
-
what error?
Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus
-
use try catch and catch the exxception
Regards, Satips.:rose: Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Walk beside me, and just be my friend. - Albert Camus
-
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
$h@ma!|@
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 ";
"AND" operator will be join with Textbox1.Text so give spance there Best Regard PathanGOD HELP THOSE WHO HELP THEMSELVES
-
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 ";
"AND" operator will be join with Textbox1.Text so give spance there Best Regard PathanGOD HELP THOSE WHO HELP THEMSELVES
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 "; User this string best Regard Pathan
GOD HELP THOSE WHO HELP THEMSELVES
-
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 ";
"AND" operator will be join with Textbox1.Text so give spance there Best Regard PathanGOD HELP THOSE WHO HELP THEMSELVES
-
check this also "tbl.t_id=tbl3.tb3_id" What is tbl? Best Regard Pathan
GOD HELP THOSE WHO HELP THEMSELVES
-
check this also "tbl.t_id=tbl3.tb3_id" What is tbl? Best Regard Pathan
GOD HELP THOSE WHO HELP THEMSELVES
-
well tbl is the tablename in databases..actually these are not the actual tablenames but it was to simplify the query to post
$h@ma!|@
I've always found using string.format rather than concatentation helps to simplify things like this and makes the code more readable so you can find syntax errors better. Of course using a stored proc, as you should, this is not an issue.
only two letters away from being an asset