User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,003 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,401 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 5216 | Replies: 0
Reply
Join Date: Jul 2004
Posts: 64
Reputation: koh is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
koh koh is offline Offline
Junior Poster in Training

Help GridView Insert Problem

  #1  
Feb 24th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 9:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC