Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public void Add_scheduled(object sender, EventArgs e)
   {
       String sql;
       sql = "insert into dbo.b_schedule";
       sql = sql + "(sdate,scost,sremark,ano)";
       sql = sql + "values(Convert(date,'" + adddate.Text + "',103),";
       sql = sql + Convert.ToDouble(Mcost.Text) + ",";
       sql = sql + "'" + Mremark.Text + "',";
       sql = sql + uano.Text + ")";
       c.executeqry(sql);
       adddate.Text = string.Empty;
       Mcost.Text = string.Empty;
       Mremark.Text = string.Empty;
       uano.Text = string.Empty;

       Response.Redirect("BQS.aspx");
   }

C#
public void Add_unscheduled(object sender, EventArgs e)
    {
        String sql;
        sql = "insert into dbo.b_unschedule";
        sql = sql + "(udate,ucost,d_date,d_reason,uremark,ano)";
        sql = sql + "values(Convert(date,'" + mdate.Text + "',103),";
        sql = sql + Convert.ToDouble(ucost.Text) + ",";
        sql = sql + "'" + ureason.Text + "',";
        sql = sql + "'" + udamage.Text + "',";
        sql = sql + "'" + uremark.Text + "',";
        sql = sql + uano.Text + ")";


        c.executeqry(sql);
        mdate.Text = string.Empty;
        ucost.Text = string.Empty;
        ureason.Text = string.Empty;
        udamage.Text = string.Empty;
        uremark.Text = string.Empty;
        uano.Text = string.Empty;
        Response.Redirect("BQS.aspx");
    }
Posted
Comments
_Maxxx_ 17-Jul-13 1:15am    
It would REALLY help if you told us what errors you were getting, and where!
anjali02199 17-Jul-13 1:29am    
Incorrect syntax near ')'.
Line 29: cmd.ExecuteNonQuery():(the error is being generated for add_scheduled )
[no name] 17-Jul-13 1:15am    
Hi Anjali,
Where is ur question?
Improve ur question by comments like
what help u needed? what u tried? what r d issues u have faced?

No one will help u for simple "not able to correct the errors"
praks_1 17-Jul-13 1:20am    
problem is in the date format
anjali02199 17-Jul-13 1:30am    
can u please make the correction and write it over here.

You say that the error is at
Line 29: cmd.ExecuteNonQuery()
but nowhere in your code snippets can that line be found!
Instead of concatenating strings to create a query, you'd better use parameterized queries. Apart from some proetction against SQL injection attacks (something you haven't thought of, have you?), they deal perfectly with date/time values, non-ASCII-characters, number formats, and such things. The incorrect syntax of your SQL query will likely be solved by that change too.
 
Share this answer
 
 
Share this answer
 
v2
public void Add_scheduled(object sender, EventArgs e)
 {
 String sql;
 String str = "server=abc;uid=sa;pwd=sa;initial catalog=master"; // define your server credentials
 SqlConnection cn = new SqlConnection(str);
 SqlCommand cmd;
 sql = "insert into dbo.b_schedule";
 sql = sql + "(sdate,scost,sremark,ano)";
 sql = sql + "values(" + adddate.Text + "',";
 sql = sql + Convert.ToDouble(Mcost.Text) + ",";
 sql = sql + "'" + Mremark.Text + "',";
 sql = sql + uano.Text + ")";
 cmd = new SqlCommand(sql,cn);
 cn.Open();
 c.executeqry(sql);
 cn.Close();
 adddate.Text = string.Empty;
 Mcost.Text = string.Empty;
 Mremark.Text = string.Empty;
 uano.Text = string.Empty;

 Response.Redirect("BQS.aspx");
 }
 
Share this answer
 
Use ..
SQL
insert into dbo.b_schedule(sdate,scost,sremark,ano) values
(
Convert(date,'" + adddate.Text + "',103),"+Convert.ToDouble(Mcost.Text)+",'"+Mremark.Text+"','"+uano.Text+"'
)
 
Share this answer
 
Use ..
SQL
insert into b_schedule(sdate,scost,sremark,ano) values
(
Convert(date,'" + adddate.Text + "',103),"+Convert.ToDouble(Mcost.Text)+",'"+Mremark.Text+"','"+uano.Text+"'
)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900