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
magesh manavalan
NA
331
508.3k
i have some errors and i sent my code
Dec 27 2011 3:24 AM
Am getting this Error.
Line1:incorrect syntex near')'.
Exception: System.Data.SQLException:Line1 incorrect syntex
Line 44 : SqlDataReader dr = cmd.ExecuteReader();
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Default2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=CRMS;Trusted_Connection=True");
string str;
SqlCommand cmd;
int count;
protected void Page_Load(object sender, EventArgs e)
{
Label5.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
////str = "insert into Project values('"+TextBox1.Text+"','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + ")";
////cmd = new SqlCommand(str, con);
////cmd.ExecuteNonQuery();
////Response.Write("Record inserted Successfully");
////con.Close();
str = "Select * from Project where Project_Name='" + TextBox2.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
{
str = "insert into Project values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + ")";
SqlCommand cmd1 = new SqlCommand(str, con);
//cmd = new SqlCommand(str, con);
cmd1.ExecuteNonQuery();
Response.Write("Record inserted Successfully");
con.Close();
}
con.Open();
SqlCommand cmd3 = new SqlCommand("select * from Project ", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text="";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void Button3_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Project where Project_Code = '" + TextBox5.Text + "'", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void Button4_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Project ", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[2].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[3].Text;
TextBox4.Text = GridView1.SelectedRow.Cells[4].Text;
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
}
protected void Button5_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=CRMS;Trusted_Connection=True");
con.Open();
Label5.Visible = true;
SqlCommand cmd2 = new SqlCommand("Update Project set Cost = " + TextBox4.Text + " where Project_Code = '" + TextBox1.Text + "'", con);
cmd2.ExecuteNonQuery();
// Response.Write("Record Updated successfully");
Label5.Text = "Record Updated successfully";
SqlCommand cmd1 = new SqlCommand("select * from Project ", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
TextBox1.ReadOnly = false;
TextBox2.ReadOnly = false;
TextBox3.ReadOnly = false;
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button6_Click(object sender, EventArgs e)
{
str = "select count(*) from Project";
cmd = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(cmd.ExecuteScalar()) + 1;
TextBox1.Text = "P000" + count;
con.Close();
TextBox2.Enabled = true;
TextBox3.Enabled = true;
}
protected void Button7_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
}
Reply
Answers (
1
)
Nested Class Problem in C#
REFRESHIN DATA WITHOUT REFRESH BUTTON(REFRESH DATA TABLE DATA)