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