Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
MY CODE IS :

VB
string query="select DISPATCH.Bill_No, NWTHAN.Quality, NWTHAN.Than_No, NWTHAN.Length, NWTHAN.Weight, NWTHAN.Tobaleno "+
                           "from DISPATCH , BALES , NWTHAN"+
                           "where DISPATCH.Bill_no='" + comboBox1.SelectedValue.ToString() + "' and BALES.Bill_No=DISPATCH.Bill_no and NWTHAN.Tobaleno=BALES.Bale_No" +
                            "order by NWTHAN.Than_No";



HELP ME !!!
Posted
Comments
Arjsrya 5-Jan-15 4:17am    
Why don't you try store procedure?Did you debug the code?Does it frame the correct sql syntax?
Tomas Takac 5-Jan-15 4:21am    
Have a look on what's actually in query, then it will be much clearer. If it's not, try to run the statement directly (in SSMS perhaps?).

You have two problems:
1. Your code is wide open to SQL injection...Never use string concatenation to create queries, use parametrized queries!
2. You do not add spaces between the parts of the query...
This:
C#
"from DISPATCH , BALES , NWTHAN"+
"where DISPATCH.Bill_no='"

Is equal to his:
C#
"from DISPATCH , BALES , NWTHANwhere DISPATCH.Bill_no='"

As you can see no space between the last able and the where...
You have the very same at the order by...
 
Share this answer
 
1.The first error that I saw is that you forgot to let a space before to add "WHERE" clause, ans also before "order by".

2.So you should change your SQL like this:
C#
string query="select DISPATCH.Bill_No, NWTHAN.Quality, NWTHAN.Than_No, NWTHAN.Length, NWTHAN.Weight, NWTHAN.Tobaleno "+
                           "from DISPATCH , BALES , NWTHAN "+ //Here was the problem!
                           "where DISPATCH.Bill_no='" + comboBox1.SelectedValue.ToString() + "' and BALES.Bill_No=DISPATCH.Bill_no and NWTHAN.Tobaleno=BALES.Bale_No " //Also here a similar problem! 
                            +"order by NWTHAN.Than_No";
 
Share this answer
 
SQL
string query = @"select DISPATCH.Bill_No, NWTHAN.Quality, NWTHAN.Than_No, NWTHAN.Length, NWTHAN.Weight, NWTHAN.Tobaleno
                           from DISPATCH , BALES , NWTHAN
                           where DISPATCH.Bill_no= " + comboBox1.SelectedValue.ToString() + " and BALES.Bill_No=DISPATCH.Bill_no and NWTHAN.Tobaleno=BALES.Bale_No order by NWTHAN.Than_No";
 
Share this answer
 
VB
string query="select DISPATCH.Bill_No, NWTHAN.Quality, NWTHAN.Than_No, NWTHAN.Length, NWTHAN.Weight, NWTHAN.Tobaleno "+
                           "from DISPATCH , BALES , NWTHAN"+
                           " where DISPATCH.Bill_no='" + comboBox1.SelectedValue.ToString() + "' and BALES.Bill_No=DISPATCH.Bill_no and NWTHAN.Tobaleno=BALES.Bale_No" +
                            " order by NWTHAN.Than_No";


just add space before where and order by clause. your query will run fine.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900