That would explain why it isn't showing up in your database.
Looking at your code (above) I only see the Selection and EnterQty as parameters to your SQL statment.
You're leaning an important lesson here, if you don't put it in the database, it won't show up in the database. The database is not an all knowing thing, it is a dumb storage device that only stores what it is given to store.
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
foreach (GridViewRow gvr in GridView1.Rows)
{
string data1 = ((Label)gvr.FindControl("Label12")).Text;
string data2 = ((Label)gvr.FindControl("LAP")).Text.Trim();
if(data2.Substring(data2.Length-1, 1) !='%') {
data2 =data2 + '%'
}
SqlCommand c = new SqlCommand("INSERT INTO Order(Rate,AP) VALUES (@Rate,@AP)", conn);
c.Parameters.Add(new SqlParameter("@Rate", data1));
c.Parameters.Add(new SqlParameter("@AP", data2));
c.ExecuteNonQuery();
}
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: CS0019: Operator '!=' cannot be applied to operands of type 'string' and 'char'
Source Error:
Line 68:
Line 69:
Line 70: if (data2.Substring(data2.Length - 1, 1) != '%') Line 71: {
Line 72: data2 = data2 + '%';
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
foreach (GridViewRow gvr in GridView1.Rows)
{
string data1 = ((Label)gvr.FindControl("Label12")).Text;
string data2 = ((Label)gvr.FindControl("LAP")).Text.Trim();
if(data2.Substring(data2.Length-1, 1) !="%") {
data2 =data2 + '%'
}
SqlCommand c = new SqlCommand("INSERT INTO Order(Rate,AP) VALUES (@Rate,@AP)", conn);
c.Parameters.Add(new SqlParameter("@Rate", data1));
c.Parameters.Add(new SqlParameter("@AP", data2));
c.ExecuteNonQuery();
}
StartIndex cannot be less than zero.
Parameter name: startIndex
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Priya_here
Member
709 Points
1854 Posts
Gridview itemtemplate label values not storing in database table
Dec 25, 2012 02:40 PM|LINK
hi..
This is my gridview
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="CS" ShowFooter="True" style="left: 3px; position: absolute; top: 144px" Font-Bold="True" Font-Names="Palatino Linotype" Font-Size="12pt" ForeColor="Teal" Width="296px"> <Columns> <asp:TemplateField HeaderText="Rate"> <EditItemTemplate> <asp:TextBox ID="TextBox12" runat="server" Text='<%# Bind("Rate") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label12" runat="server" Text='<%# Bind("Rate") %>'></asp:Label> </ItemTemplate> <HeaderStyle ForeColor="Maroon" /> </asp:TemplateField> <asp:TemplateField HeaderText="Actual Percentage"> <ItemTemplate> <asp:Label ID="LAP" runat="server" CssClass="myCss" TabIndex="7" Width="73px"></asp:Label> </ItemTemplate> <FooterStyle VerticalAlign="Bottom" /> <HeaderStyle Width="40px" ForeColor="Maroon" /> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView>onload gridview look like this
A 10%
B 40%
C 60%
On button click all my gridview data i store in to data base table
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); foreach (GridViewRow gvr in GridView1.Rows) { string data1 = ((Label)gvr.FindControl("Label12")).Text; string data2 = ((Label)gvr.FindControl("LAP")).Text; SqlCommand c = new SqlCommand("INSERT INTO Order(Rate,AP) VALUES (@Rate,@AP)", conn); c.Parameters.Add(new SqlParameter("@Rate", data1)); c.Parameters.Add(new SqlParameter("@AP", data2)); c.ExecuteNonQuery(); }on button click it shows like this in database table only
A B C not percentange...why its not inserting percentange in database table..
Thanks
eric2820
Contributor
2777 Points
1161 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 25, 2012 03:14 PM|LINK
What is the datatype in your database?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Priya_here
Member
709 Points
1854 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 25, 2012 03:17 PM|LINK
its datatype is varchar(250)
Priya_here
Member
709 Points
1854 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 25, 2012 03:32 PM|LINK
this gridview i store in database table
http://forums.asp.net/t/1867880.aspx/1?Gridview+to+calculate+percenatge+value+based+on+textbox+value
Selection EnterQty Percentage
A 500 12.5%
B 2000 50%
C 1500 37.5%
eric2820
Contributor
2777 Points
1161 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 25, 2012 04:59 PM|LINK
Is the Percentage column a calcualted value?
That would explain why it isn't showing up in your database.
Looking at your code (above) I only see the Selection and EnterQty as parameters to your SQL statment.
You're leaning an important lesson here, if you don't put it in the database, it won't show up in the database. The database is not an all knowing thing, it is a dumb storage device that only stores what it is given to store.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
oned_gk
All-Star
31003 Points
6345 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 25, 2012 11:49 PM|LINK
Your code looks good.
Check to new records, dont look to current records because you have do inserting record not updating records.
sameer_khanj...
Contributor
7046 Points
1376 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 26, 2012 05:43 AM|LINK
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); foreach (GridViewRow gvr in GridView1.Rows) { string data1 = ((Label)gvr.FindControl("Label12")).Text; string data2 = ((Label)gvr.FindControl("LAP")).Text.Trim(); if(data2.Substring(data2.Length-1, 1) !="%") { data2 =data2 + '%' } SqlCommand c = new SqlCommand("INSERT INTO Order(Rate,AP) VALUES (@Rate,@AP)", conn); c.Parameters.Add(new SqlParameter("@Rate", data1)); c.Parameters.Add(new SqlParameter("@AP", data2)); c.ExecuteNonQuery(); }sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
Priya_here
Member
709 Points
1854 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 26, 2012 06:54 AM|LINK
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: CS0019: Operator '!=' cannot be applied to operands of type 'string' and 'char'
Source Error:
Line 68: Line 69: Line 70: if (data2.Substring(data2.Length - 1, 1) != '%') Line 71: { Line 72: data2 = data2 + '%';sameer_khanj...
Contributor
7046 Points
1376 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 26, 2012 07:32 AM|LINK
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); foreach (GridViewRow gvr in GridView1.Rows) { string data1 = ((Label)gvr.FindControl("Label12")).Text; string data2 = ((Label)gvr.FindControl("LAP")).Text.Trim(); if(data2.Lenght>0 && data2.Substring(data2.Length-1, 1) !="%") { data2 =data2 + '%' } SqlCommand c = new SqlCommand("INSERT INTO Order(Rate,AP) VALUES (@Rate,@AP)", conn); c.Parameters.Add(new SqlParameter("@Rate", data1)); c.Parameters.Add(new SqlParameter("@AP", data2)); c.ExecuteNonQuery(); }sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
Priya_here
Member
709 Points
1854 Posts
Re: Gridview itemtemplate label values not storing in database table
Dec 26, 2012 10:27 AM|LINK
StartIndex cannot be less than zero.
Parameter name: startIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: StartIndex cannot be less than zero.