944,111 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 16180
  • ASP.NET RSS
Feb 24th, 2007
0

GridView Insert Problem

Expand Post »
Hi, i am trying to use new method in asp.net for the database connectivity. --> using gridview
yet i am facing problem here in the "adding new" area.

here goes my code:

 
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="BillID">
<Columns>
<asp:CommandField ShowInsertButton="True" />
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
<asp:TemplateField HeaderText="ItemNumber" SortExpression="ItemNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ItemNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ItemNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
<asp:BoundField DataField="InvoiceDt" HeaderText="InvoiceDt" SortExpression="InvoiceDt" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="refNumber" HeaderText="refNumber" SortExpression="refNumber" />
<asp:BoundField DataField="ItemDt" HeaderText="ItemDt" SortExpression="ItemDt" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" readonly="True"/>
<asp:TemplateField></asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBClinicConnectionString2 %>"
SelectCommand="SELECT [BillID], [InvoiceDt], [Description], [ItemNumber], [ItemDt], [refNumber], [Company], [Amount], [UnitPrice], [Quantity] FROM [BillStatement]"
UpdateCommand = "Update [BillStatement] 
SET 
Company = @Company, 
InvoiceDt = @InvoiceDt,
refNumber = @refNumber,
ItemNumber = @ItemNumber,
ItemDt = @ItemDt,
Description = @Description,
Quantity = @Quantity,
UnitPrice = UnitPrice
where BillID = @BillID " 
DeleteCommand = "Delete [BillStatement] where BillID = @BillID "
InsertCommand= "INSERT INTO [BillStatement](Company,InvoiceDt,refNumber,ItemNumber,ItemDt,Description,Quantity,UnitPrice) VALUES (@Company,@InvoiceDt,@refNumber,@ItemNumber,@ItemDt,@Description,@Quantity,@UnitPrice)" 
></asp:SqlDataSource>

</div>
</form>

</body>
</html>

The problem here is, i cant get my program to add new items.
but the other functions such as; edit, delete and view.... have no problem at all.

I would like to know what is the mistake(s) i have done in here. or am i doing the right thing?
Correct me if i am wrong.
Thank you
Similar Threads
koh
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
koh is offline Offline
73 posts
since Jul 2004
Jan 25th, 2009
-1

Re: GridView Insert Problem

have you defined insert parameters?

have you used Insert() method?

Plus, one more thing IS WRONG with the DeleteCommand.
This is correct:
DeleteCommand = "Delete FROM [BillStatement] where BillID = @BillID "
Reputation Points: 11
Solved Threads: 7
Posting Whiz in Training
Clawsy is offline Offline
225 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Grid and Data not showing up when viewing in browser
Next Thread in ASP.NET Forum Timeline: Best way to implement the find Function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC