Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello programmers, see im new here. I know my syntax is error. here is my code

<pre lang="vb">Dim strSQL As String
        Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
        strSQL = "SELECT * from tblTrainingPlan Where WHERE ([Category] = @Category)"
        connection.Open()
        Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
        myCommand.Parameters.AddWithValue("@Category", 1)
        gee.DataSource = myCommand.ExecuteReader()
        gee.DataBind()
        connection.Close()



may error is Incorrect syntax near the keyword 'WHERE'.

thanks
Posted

Take the multiple "WHERE" clauses out:
strSQL = "SELECT * from tblTrainingPlan Where WHERE ([Category] = @Category)"

becomes
strSQL = "SELECT * from tblTrainingPlan WHERE ([Category] = @Category)"
 
Share this answer
 
Comments
[no name] 10-May-11 3:02am    
my 5 for this answer
Your query has double where
strSQL = "SELECT * from tblTrainingPlan  Where WHERE [Category] = "'+@Category+'""

i thinks that is the error since the says syntax on Error
 
Share this answer
 
Comments
chaosgray 10-May-11 3:09am    
thank you sir
Dim strSQL As String
        Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL")
        strSQL = "SELECT * from tblTrainingPlan Where WHERE ([Category] = " + "1" + ")"
        connection.Open()
        Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
        gee.DataSource = myCommand.ExecuteReader()
        gee.DataBind()
        connection.Close()
 
Share this answer
 
Why you use double where in select command....Just delete one
 
Share this answer
 
Change your query like this
strSQL = "SELECT * from tblTrainingPlan Where WHERE [Category] = " + @Category
 
Share this answer
 
Comments
OriginalGriff 10-May-11 3:12am    
Reason for my vote of one: Do you really think that would compile?
try to find out in the following way

string   strSQL = "(SELECT * from yourtable  WHERE Category  =" + @Category+ ")";
 
Share this answer
 
v3
Comments
OriginalGriff 10-May-11 3:13am    
Reason for my vote of one: Do you really think that would compile? It's even worse than the one you copied it from!
janwel 10-May-11 3:17am    
hehehehe
Mahendra.p25 10-May-11 3:29am    
what is the Problem in this Query ? can You please elaborate ...........Mr Original griff.
Mahendra.p25 10-May-11 3:39am    
i have tried this and its working Properly
int @k = 25;
string Query = "(Select * from MyTable where Id=" +@k+")" ;
Cmd = new SqlCommand(Query, Con);
dt = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
dt.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Con.Close();

i think I dont need to explain that to you.....

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