magesh manavalan

magesh manavalan

  • NA
  • 331
  • 508.1k

I have four field but i am insert only three field that time show the that error Line Incorrect syntax near ')'.

Dec 26 2011 12:39 AM
Hi...,


I have four field but i am insert only three field  that time show the that error Line Incorrect syntax near ')'.  i want show the error message you should enter all values. 


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page 
{


    SqlConnection con = new SqlConnection("Server=(local);initial catalog=TNVKP_12;Trusted_Connection=True");
    string str;


    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
   
        con.Open();
     
        str = "Select * from Project  where Projectid=" + TextBox1.Text + "";
        SqlCommand cmd = new SqlCommand(str, con);
       // cmd = new SqlCommand(str, con);


        SqlDataReader dr = cmd.ExecuteReader();
     
       
        if (dr.HasRows)
        {


            Response.Write("Record already exist");
           
        }
        else
        {
            dr.Close();
            str = ("insert into Project values(" + TextBox1.Text + ",'" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + ")");


            SqlCommand cmd1 = new SqlCommand(str, con);
            cmd1.ExecuteNonQuery();


            Response.Write("Record inserted Successfully");
            con.Close();
        }


    }
}




Thanks&Regs.

Magesh.A

Answers (2)