I have write mention code but its not working.
Server Error in '/' Application.
Incorrect syntax near ')'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ')'. Source Error:
Line 62: //SqlCommand com = new SqlCommand("insert into unit_one(CO2,NO,SO2,CO,PM,FLOW) values ('" + g1.Cells[1].Text + "','" + g1.Cells[2].Text + "','" + g1.Cells[3].Text + "','" + g1.Cells[4].Text + "','" + g1.Cells[5].Text + "','" + g1.Cells[6].Text + "')", con);
Line 63: con.Open();
Line 64: com.ExecuteNonQuery();
Line 65: con.Close();
Line 66:
|
namespace ReadTxtFile
{
public partial class WebForm7 : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = "Date:" + DateTime.Now.ToString();
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Parameters"),
new DataColumn("CO2"),
new DataColumn("NO"),
new DataColumn("SO2"),
new DataColumn("CO"),
new DataColumn("PM"),
new DataColumn("Flow")
});
dt.Rows.Add("UoM", "%", "ppm", "ppm", "ppm", "mg/Nm", "m/s");
string stack1 = (new WebClient()).DownloadString("file://10.1.150.237/display%20board/STACK1UNIT1.txt");
// string stack1 = File.ReadAllText(Server.MapPath("/10.1.150.237/display%20board/STACK2UNIT2.txt"));
string stack2 = (new WebClient()).DownloadString("file://10.1.150.237/display%20board/STACK2UNIT2.txt");
string[] splitParams = new[] { "CO2", "NO", "SO2", "CO", "PM", "FLOW" };
string[] values = stack1.Split(splitParams, StringSplitOptions.RemoveEmptyEntries);
dt.Rows.Add("UNIT#1", values[0], values[1], values[2], values[3], values[4], values[5]);
values = stack2.Split(splitParams, StringSplitOptions.RemoveEmptyEntries);
dt.Rows.Add("UNIT#2", values[0], values[1], values[2], values[3], values[4], values[5]);
gridView1.DataSource = dt;
gridView1.DataBind();
GridViewRow g1 = gridView1.Rows[1];
string connStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand com = new SqlCommand("UPDATE unit_one SET CO2 = '" + g1.Cells[1].Text + "', NO = '" + g1.Cells[2].Text + "',SO2 ='" + g1.Cells[3].Text + "', CO ='" + g1.Cells[3].Text + "' ,PM ='" + g1.Cells[3].Text + "', FLOW = '" + g1.Cells[4].Text + "' where id='137')", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
g1 = gridView1.Rows[2];
con = new SqlConnection(connStr);
com = new SqlCommand("UPDATE unit_two SET CO2 = '" + g1.Cells[1].Text + "', NO = '" + g1.Cells[2].Text + "',SO2 ='" + g1.Cells[3].Text + "', CO ='" + g1.Cells[3].Text + "' ,PM ='" + g1.Cells[3].Text + "', FLOW = '" + g1.Cells[4].Text + "' where id='137')", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
}
}