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
Chevy Mark Sunderland
NA
188
167.3k
Inserting data into MySQL with ASP.NET + C#
Nov 9 2012 3:19 AM
Hello there, I need your help.
I have error and problem when tried insert into mysql table data of gridview.
If tried th same query in mysql workbench I don't have problem, instead the aspx page print this error, why?
The problem occurs when I want to run multiple inserts in mysql table.
Thank you in advance, I hope your help.
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.51-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO tbl_g (q) VALUES (2)' at line 1
The code behind
protected void btnInsert_Click(object sender, EventArgs e)
{
System.Text.StringBuilder strSql = new System.Text.StringBuilder(string.Empty);
OdbcCommand cmd = new OdbcCommand();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkUpdate = (CheckBox)
GridView1.Rows[i].Cells[0].FindControl("chkSelect");
if (chkUpdate != null)
{
if (chkUpdate.Checked)
{
strID = GridView1.Rows[i].Cells[1].Text;
strName = ((TextBox)
GridView1.Rows[i].FindControl("p")).Text;
string strQuery = "INSERT INTO tbl_g (q) VALUES (" + strName + ");";
Response.Write(strQuery);
strSql.Append(strQuery);
}
}
}
try
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql.ToString();
cmd.Connection = myConnectionString;
myConnectionString.Open();
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string errorMsg = "Error";
errorMsg += ex.Message;
throw new Exception(errorMsg);
}
finally
{
myConnectionString.Close();
}
UncheckAll();
}
Reply
Answers (
1
)
Converting Assembly, its Classes and its properties to an XML file after assigning the values to all properties using Reflection
Could not load file or assembly 'System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, Public...