Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a GridView panel which will show all the data from sql database.
Below are my code.
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                con.Open();
                string all = "select [Board_Name] AS Board, [Platform], [Location], [Status], [CheckOutDate] AS Date, [AssignTo] AS Assigned from Board";
                SqlCommand cmd2 = new SqlCommand(all, con);
                SqlDataReader result2 = cmd2.ExecuteReader();
                GridView1.DataSource = result2;
                GridView1.DataBind();
                result2.Close();
                con1.Close();

While debugging, "Incorrect Syntax Near 'Number'" message are shown at line "SqlDataReader result2 = cmd2.ExecuteReader();"..

May anyone please review and tell me what's wrong? :(
Posted
Updated 13-Jun-13 17:55pm
v2
Comments
Christian Graus 13-Jun-13 22:55pm    
What happens if you run that SQL inside SQL Server Management studio ? There's obvious bad design issues here, but I don't see any reason for that code not to run, assuming the columns are correct and you're connecting to the right DB.
GrAp3 13-Jun-13 23:16pm    
hmm.. everything goes well...

I think you should test Connection String and query SQL.
I do it and not problem.
 
Share this answer
 
Comments
GrAp3 13-Jun-13 23:15pm    
there's no problem while test connection...
Thắng Cv 13-Jun-13 23:22pm    
This is My code.
String conn = "Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection connect = new SqlConnection(conn);
connect.Open();
string query= "select * from Customers";
SqlCommand command = new SqlCommand(query,connect);
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();

There's no problem.I do it success
GrAp3 13-Jun-13 23:36pm    
i'm not sure what happen .. but i recreate another web apps and sqldb.. it's work now..
Thắng Cv 14-Jun-13 0:26am    
Sometime i recreate another web apps and it's work.
I learning asp.net.I can help you and you too.
do you have account facebook ?
just recreate... think is some setting problem..
 
Share this answer
 

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