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
selvi subramanian
NA
799
572.8k
there is no error but edit and delete is not working
Jun 28 2014 4:19 AM
private void BindData()
{
string strQuery = "select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount" + " from suplerrate";
SqlCommand cmd = new SqlCommand(strQuery);
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
private DataTable GetData(SqlCommand cmd)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
protected void EditCustomer(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void AddNewCustomer(object sender, EventArgs e)
{
string nm = ((TextBox)GridView1.FooterRow.FindControl("txbna")).Text;
string BNo = ((TextBox)GridView1.FooterRow.FindControl("txnbno")).Text;
string bdate = ((TextBox)GridView1.FooterRow.FindControl("txtbildate")).Text;
string adre = ((TextBox)GridView1.FooterRow.FindControl("txtadrsse")).Text;
string phn = ((TextBox)GridView1.FooterRow.FindControl("txtphnebin")).Text;
string emil = ((TextBox)GridView1.FooterRow.FindControl("txtemidl")).Text;
string supfr = ((TextBox)GridView1.FooterRow.FindControl("txtsupfor")).Text;
string bbd = ((TextBox)GridView1.FooterRow.FindControl("txtbnd")).Text;
string bigt = ((TextBox)GridView1.FooterRow.FindControl("txtbingnnt")).Text;
string vatt = ((TextBox)GridView1.FooterRow.FindControl("txvaatb")).Text;
string bdiste = ((TextBox)GridView1.FooterRow.FindControl("txtdiscnt")).Text;
string tool = ((TextBox)GridView1.FooterRow.FindControl("txttoool")).Text;
string pentg = ((TextBox)GridView1.FooterRow.FindControl("txtpecntge")).Text;
string txtamt = ((TextBox)GridView1.FooterRow.FindControl("txtamnut")).Text;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into suplerrate(Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount) " +
"values(@Name, @BillNo, @BillDate,@Address,@Phone,@EmailId,@Supplierfor,@Brand,@Billingrate,@vat,@discount,@total,@percentage,@amount);" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount from suplerrate";
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = nm;
cmd.Parameters.Add("@BillNo", SqlDbType.VarChar).Value = BNo;
cmd.Parameters.Add("@BillDate", SqlDbType.VarChar).Value = bdate;
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = adre;
cmd.Parameters.Add("@Phone", SqlDbType.BigInt).Value = phn;
cmd.Parameters.Add("@EmailId", SqlDbType.VarChar).Value = emil;
cmd.Parameters.Add("@Supplierfor", SqlDbType.VarChar).Value = supfr;
cmd.Parameters.Add("@Brand", SqlDbType.VarChar).Value = bbd;
cmd.Parameters.Add("@Billingrate", SqlDbType.Float).Value = bigt;
cmd.Parameters.Add("@vat", SqlDbType.Float).Value = vatt;
cmd.Parameters.Add("@discount", SqlDbType.Float).Value = bdiste;
cmd.Parameters.Add("@total", SqlDbType.Float).Value = tool;
cmd.Parameters.Add("@percentage", SqlDbType.Float).Value = pentg;
cmd.Parameters.Add("@amount", SqlDbType.Float).Value = txtamt;
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
protected void CancelEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text;
string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text;
string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text;
string phn = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtphnebin")).Text;
string emil = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtemidl")).Text;
string supfr = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsupfor")).Text;
string bbd = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbnd")).Text;
string bigt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbingnnt")).Text;
string vatt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txvaatb")).Text;
string bdiste = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdiscnt")).Text;
string tool = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txttoool")).Text;
string pentg = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpecntge")).Text;
string txtamt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtamnut")).Text;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update suplerrate set BillNo=@BillNo," + "BillDate=@BillDate," + "Address=@Address, " + " Phone=@Phone ," + " EmailId=@EmailId," + "Supplierfor=@Supplierfor," + "Brand=@Brand," + "Billingrate=@Billingrate," + "vat=@vat," + "discount=@discount," + "total=@total," + "percentage=@percentage," + "amount=@amount where Name=@Name;" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount from suplerrate";
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = nm;
cmd.Parameters.Add("@BillNo", SqlDbType.VarChar).Value = BNo;
cmd.Parameters.Add("@BillDate", SqlDbType.VarChar).Value = bdate;
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = adre;
cmd.Parameters.Add("@Phone", SqlDbType.BigInt).Value = phn;
cmd.Parameters.Add("@EmailId", SqlDbType.VarChar).Value = emil;
cmd.Parameters.Add("@Supplierfor", SqlDbType.VarChar).Value = supfr;
cmd.Parameters.Add("@Brand", SqlDbType.VarChar).Value = bbd;
cmd.Parameters.Add("@vat", SqlDbType.Float).Value = vatt;
cmd.Parameters.Add("@discount", SqlDbType.Float).Value = bdiste;
cmd.Parameters.Add("@total", SqlDbType.Float).Value = tool;
cmd.Parameters.Add("@percentage", SqlDbType.Float).Value = pentg;
cmd.Parameters.Add("@amount", SqlDbType.Float).Value = txtamt;
GridView1.EditIndex = -1;
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
protected void DeleteCustomer(object sender, EventArgs e)
{
LinkButton lnkRemove = (LinkButton)sender;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from suplerrate where " +
"Name=@Name;" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount from suplerrate";
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = lnkRemove.CommandArgument;
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
Reply
Answers (
1
)
How to store and access the database locally in application?
in a table the following are the data are saved