1

I have an Excel workbook which contains data in different sheets. I want to update excel workbook using asp.net.

In asp.net, I am using following query to update excel data:

OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["SportTech"].ConnectionString);
OdbcCommand cmd;
con.Open();

string name = "sandeep";
string pos = "1";
string time = "11";
string point = "70";

string query = "UPDATE [Sheet1$] SET POSITION=\"" + pos + "\",Time=\"" + time + "\",Point=\"" + point + "\" WHERE NAME=" + name;

cmd = new OdbcCommand(query,con);
string x = cmd.ExecuteNonQuery().ToString();
MessageBox.Show(x.ToString());

but the query is showing error

ERROR [42000Ձ] [Microsoft][ODBC Excel Driver] Syntax error in UPDATE statement.

Thanks!

1
  • can anyone help me in this question Commented Sep 12, 2013 at 7:54

1 Answer 1

1

Put excel file into App_Data foldet in your site.

You can try this:

string name = "sandeep";
string pos = "1";
string time = "11";
string point = "70";
string conStr = @"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" +
@"DBQ=|DataDirectory|\SportTech.xls;ReadOnly=0;";
OdbcConnection con = new OdbcConnection(conStr);
con.Open();
string query = "update [Sheet1$] set [POSITION]=?,[Time]=?,[Point]=? where [NAME]=?";
OdbcCommand cmd = new OdbcCommand(query, con);
cmd.Parameters.AddWithValue("?", pos);
cmd.Parameters.AddWithValue("?", time);
cmd.Parameters.AddWithValue("?", point);
cmd.Parameters.AddWithValue("?", name);
cmd.ExecuteNonQuery();
con.Close();
Sign up to request clarification or add additional context in comments.

1 Comment

@ Sunny Sandeep - in left answer exist a mark picture. you can click on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.