TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
soroush parsi
NA
13
0
error in reading table from a sql database C#
Jun 11 2017 8:25 PM
Hello
I am beginner in sql and now I want to read or write to a table in a local database and I get this error:
>
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect syntax near the keyword 'Table'.
my code is here:
using (SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = c:\users\soroush\documents\visual studio 2015\Projects\databasetest2\databasetest2\Database1.mdf; Integrated Security = True"))
{
con.Open();
string t = "SELECT * From Table";
SqlCommand cmd = new SqlCommand(t, con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MessageBox.Show(reader["Id"].ToString() + reader["name"].ToString());
}
con.Close();
}
the error points to this line of my code when i want to write on table:
>
SqlDataReader reader = cmd.ExecuteReader();
and I have a database whit one table named "Table" contains two columns; Id(int) and name(nchar10)
how cand i read this table and use the contents in my code?
thank you
Reply
Answers (
2
)
how to generate loan balance sheet totalamt,paidamt,total
Display report in SQL server 2012