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
who cares
NA
5
987
SQLException Unhandled Syntax error near ')'
Jun 5 2015 5:33 AM
Following is the code snippet i wrote for taking values from all the rows of a dataGridView and insert them into a table. The
table name is stored in a string variable subtable.
During debugging an
exception occurs at the y.ExecuteNonQuery() line saying:
SQLException Unhandled
Syntax error near ')'
x = new SqlConnection("Data Source= AHSUYA ;initial catalog=master;integrated security=sspi;");
x.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
y = new SqlCommand("Insert into " + subtable + "values(@a,@b,@c)",x);
y.Parameters.AddWithValue("@a", dateTimePicker1.Value.Date.ToShortDateString());
y.Parameters.AddWithValue("@b", dataGridView1.Rows[i].Cells[0].Value.ToString());
y.Parameters.AddWithValue("@c", dataGridView1.Rows[i].Cells[1].Value.ToString());
y.ExecuteNonQuery();
}
x.Close();
I cannot determine whats wrong with the code ... please help me out !!!
Reply
Answers (
6
)
Datagridview to excel
How to Truncate Data in c#