Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2007, 03:04 AM
Authorized User
 
Join Date: Jun 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Column does not belong to table error

Problem: Column 'xxxxxx' does not belong to table when Adding a empty row to a datagrid.

Hello, I have form that allows me to enter multiple items and perform a batch insert into the DB. I want to add a button, Add Row_Click to add aditional rows without losing the data already in the grid, But I am running into problem using the Add Row Click and receive the error: Column 'CustomerID' does not belong to table. Please tell me what I am doing wrong?


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim DT As New DataTable
If (Not Page.IsPostBack) OrElse (Not (TypeOf Session("DT") Is DataTable)) Then

'Create Empty Datatable
'DT = CType(gvParts.DataSource, DataTable)
DT = New DataTable("AddExtraRow")
'DT.Columns.Add("LN", Type.GetType("System.String"))
DT.Columns.Add("CustomerID", Type.GetType("System.String"))
DT.Columns.Add("BarcodeAttached", Type.GetType("System.String"))
DT.Columns.Add("Barcode", Type.GetType("System.String"))
DT.Columns.Add("RevisionPart", Type.GetType("System.String"))
DT.Columns.Add("RevisionDescription", Type.GetType("System.String"))
DT.Columns.Add("ComponentLoaction", Type.GetType("System.String"))
DT.Columns.Add("LocationID", Type.GetType("System.String"))
DT.Columns.Add("Part_SerialNumber", Type.GetType("System.String"))
DT.Columns.Add("Part_number", Type.GetType("System.String"))
DT.Columns.Add("UPC", Type.GetType("System.String"))
DT.Columns.Add("unit_price", Type.GetType("System.String"))
DT.Columns.Add("PropertyTypeID", Type.GetType("System.String"))
DT.Columns.Add("ComponentClassification", Type.GetType("System.String"))
DT.Columns.Add("RecvCondition", Type.GetType("System.String"))
DT.Columns.Add("Received_Qty", Type.GetType("System.String"))
DT.Columns.Add("UOI", Type.GetType("System.String"))
DT.Columns.Add("ConditionCodeID", Type.GetType("System.String"))
DT.Columns.Add("Time_stamp_Received", Type.GetType("System.String"))
DT.Columns.Add("Remarks", Type.GetType("System.String"))

'Store the table in the Session variable
Session("DT") = DT

' Bind the DataGrid to an empty table
'gvParts.DataSource = DT
' gvParts.DataBind()

Else
' Retrieve the table from the session variable
DT = CType(Session("DT"), DataTable)
End If

End Sub

Protected Sub AddRow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddRow.Click

If (IsNumeric(RowCount.Text)) Then
Dim i As Integer
For i = 1 To CInt(RowCount.Text)
Dim DT As New DataTable
Dim DR As DataRow = DT.NewRow()
DR("CustomerID") = RowCount.Text
DT.Rows.Add(DR)

'Bind & Show New row(s) in grid
gvParts.DataSource = DT
gvParts.DataBind()
Next
End If

End Sub

************************************************** **
Reference to the form below is created
*************************

Receiving Form Example
*****************************
RecivingID______ # of Line Items______ MkGrid

LineNO | Part# | PartSerial# | PartName | Qty | Remarks
---------------------------------------------------------------------------
1.
2.
3.
4
5
Add Extra Rows Click____


Place a "Make grid" button next to the # of Line Items. When the user has filled in the number and clicked the button, put something like the following in the button click method.......

Create a new datatable and populate a column with the # of Line Items:
Protected Sub MakeGrid_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim dt As New Data.DataTable
dt.Columns.Add(New Data.DataColumn("LineNO"))
For i As Integer = 1 To tbItems.Text
Dim dr As Data.DataRow
dr = dt.NewRow
dr("LineNO") = i
dt.Rows.Add(dr)
Next
'Bind the DataTable to the DataGrid
gvParts.DataSource = dt
gvParts.DataBind()


The gridview will need to have six columns. The first one will just be a bound column to the LineNO column of the data table. The following Five columns will be template columns with text boxes :
Note I left out the other fields Template fields to save space.

<asp:GridView ID="gvParts" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="PartNo" />
<asp:TemplateField HeaderText="Part #">
<ItemTemplate>
<asp:TextBox ID="part_number" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Then when they submit their form, I want to iterate through the rows of the gridview, getting the textbox values and inputting into database

Note I left out the other fields Template fields to save space.

Protected Sub AddReceiving_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddReceiving.Click

'Add new received components to the receiving table
Dim tblReceiving As New partdb.tblReceivingDataTable()
For Each gvr As GridViewRow In gvParts.Rows
If gvr.RowType = DataControlRowType.DataRow Then

'Add a new ProductsRow to the Receiving DataTable
Dim part_number As TextBox = CType(gvr.


'Add a new receiving row to the to the ReceivingDataTable
Dim newReceiving As partdb.tblReceivingRow = tblReceiving.NewtblReceivingRow()

' Assign the values from the web page
newReceiving.Part_number = part_number.Text

' Add any "default" values
newReceiving.Archive = False
newReceiving.ProcessFlag = False
newReceiving.time_stamp_entry = Date.Now
tblReceiving.AddtblReceivingRow(newReceiving)
End If
Next

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
hide certain column in a table lscjtw XSLT 2 August 2nd, 2007 01:26 PM
I added a column to a table, but, I can't see it. furjaw SQL Language 1 July 3rd, 2007 09:24 PM
getting identity column from the table g_vamsi_krish SQL Server 2000 1 March 15th, 2006 05:05 PM
Cheking if a user belong to a group marino22 VBScript 3 November 21st, 2005 08:58 AM
how to make column of table 1 = to column of table gilgalbiblewheel Classic ASP Databases 4 October 11th, 2004 11:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.