while update i have error
my source code is
Font-Names = "Arial" Font-Size = "11pt" BackColor="White"
AlternatingRowStyle-BackColor = "#C2D69B" HeaderStyle-BackColor = "pink"
ShowFooter="true" onrowediting="EditCustomer"
onrowcancelingedit="CancelEdit"
onrowupdating="UpdateCustomer">
<%--
--%>
Text = "Delete" OnClick = "DeleteCustomer">
my code is
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 BNo = Convert.ToInt32(Bo)
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;" +
cmd.CommandText = "update suplerrate set BillNo=@BillNo," + "BillDate=@BillDate," + "Address=@Address, " + " Phone=@Phone ," + " EmailId=@EmailId," + "Supplierfor=@Supplierfor," + "Brand=@Brand where Name=@Name;" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand from suplerrate";
// "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.Int).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();
}
my error is
An exception of type 'System.NullReferenceException' occurred in App_Web_ll8dodpz.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
it show this line
string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
my sql table is
CREATE TABLE [dbo].[suplerrate](
[Name] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillNo] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillDate] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Phone] [bigint] NULL,
[EmailId] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Supplierfor] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Brand] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Billingrate] [float] NULL,
[vat] [float] NULL,
[discount] [float] NULL,
[total] [float] NULL,
[percentage] [float] NULL,
[amount] [float] NULL
) ON [PRIMARY]


Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 4, 2014, 2:23 AM EDT
if i m not wrong the issue is in below code because when you are trying to find the control value it is not finding, because it is in footer templeten
try like this when you are fetching the data.
selvi subramanianRank #2,007 · 723 reputationPosted Jul 4, 2014, 2:39 AM EDT
Server Error in '/bramandam site' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.TextBox' to 'string' Source Error: Line 401: Line 402: string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text; Line 403: string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")); Line 404: string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text; Line 405: string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text; Source File: d:\bramandam site\stockentry.aspx.cs Line: 403 Show Detailed Compiler Output: Show Complete Compilation Source: Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 4, 2014, 2:55 AM EDT
BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
Server Error in '/bramandam site' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.TextBox' to 'string' Source Error: Line 401: Line 402: string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text; Line 403: string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")); Line 404: string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text; Line 405: string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text; Source File: d:\bramandam site\stockentry.aspx.cs Line: 403 Show Detailed Compiler Output: Show Complete Compilation Source: Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
selvi subramanianRank #2,007 · 723 reputationPosted Jul 4, 2014, 3:31 AM EDT
An exception of type 'System.NullReferenceException' occurred in App_Web_ll8dodpz.dll but was not handled in user code Additional information: Object reference not set to an instance of an object.
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 5, 2014, 11:20 PM EDT
BNo=((TextBox)GridView1.FooterRow[e.RowIndex].FindControl("txnbno")).Text;
and any text box u are using in Footer uhave to use FooterRow[e.RowIndex]. for finding the control and value.
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 7, 2014, 11:57 PM EDT
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text;
string BNo = ((TextBox)GridView1.FooterRow.FindControl("txnbno")).Text;
//string BNo = Convert.ToInt32(Bo)
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.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;" +
cmd.CommandText = "update suplerrate set BillNo=@BillNo," + "BillDate=@BillDate," + "Address=@Address, " + " Phone=@Phone ," + " EmailId=@EmailId," + "Supplierfor=@Supplierfor," + "Brand=@Brand where Name=@Name;" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand from suplerrate";
// "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.Int).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();
}