Data TAble declaration Problem

B

BIJU

Hai,
I am very new in ASP.NET. I wnat to use Data Table in my project. For that
When I created an instance variable of data Table like "Dim dtable as
DataTable" I got an error mesage of "Type Expected". I dont know what is
wrong with declaration. So kindly provide solution and thanks in advance
BIJU










































































































































































































































































































































































































































































+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
++
 
M

Milosz Skalecki [MCAD]

Hi there,

Add
Imports System.Data
at the top of the class file

regards
 
B

BIJU

Hai Milosz Skalecki ,
Thanks 4 ur effort
I already imported System.Data namespace. I also impoted
system.Data.Sqlclient
So pls give help and thanks in advance
BIJU
 
M

Milosz Skalecki [MCAD]

Show what you've got
--
Milosz


BIJU said:
Hai Milosz Skalecki ,
Thanks 4 ur effort
I already imported System.Data namespace. I also impoted
system.Data.Sqlclient
So pls give help and thanks in advance
BIJU
 
B

BIJU

Hai,
Thanks 4 ur response...
I am still getting error as "Type Expected"
My code is just declaration only
Creating the dataset and data table and data base connection
Data Table declaration has the problem
Dim dtable as DataTable
Kindly give reply and thanks inAdvance
BIJU
 
M

Milosz Skalecki [MCAD]

Howdy,

Please copy entire class declaraton with all the methods you have, don't be
shine :)
 
B

BIJU

Hello,
Thanks 4 ur response..
I providing here the code for the Datatable


Private Sub Button_add_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dtable As datatable
Dim dcolum As DataColumn
Dim drow As DataRow
dtable = New datatable("BLOCK")
dcolum = New DataColumn("Product ID", GetType(Int32))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Name", GetType(String))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Category", GetType(String))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Price", GetType(Decimal))
dtable.columns.Add(dcolum)

drow = New DataRow
drow("Product ID") = 23
drow("Product Name") = "Chithra"
drow("Product Category") = "Magazine"
drow("Product Price") = 50
dtable.rows.add(drow)

For Each drow In dtable.rows
For Each dcolum In dtable.columns
Response.Write(drow(dcolum))
Next
Next
End Sub

Kindly give solution and thanks in Advance
 
B

BIJU

Hai
Thanks 4 ur reply
Here is the code of entire class file
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents DataGrid2 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dset As DataSet
Dim con As SqlConnection
Dim adpter As SqlDataAdapter
dset = New DataSet
Dim dcol As DataColumn
con = New SqlConnection("workstation
id=BIJU;UID=sa;PWD=surabhi;packet size=4096;integrated security=false;initial
catalog=election05;persist security info=False")
con.Open()
adpter = New SqlDataAdapter("select * from block_mast where
dist_code = 11 order by b_code", con)
adpter.Fill(dset, "block_mast")
dcol = New DataColumn("NO. of wards", GetType(Decimal))
dcol.Expression = "count(no_wards)"
dset.Tables("block_mast").Columns.Add(dcol)
DataGrid1.DataSource = dset
DataGrid1.DataMember = "Block_mast"
DataGrid1.DataBind()
End Sub

Private Sub Button_add_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dtable As datatable()
Dim dcolum As DataColumn
Dim drow As DataRow
dtable = New datatable("BLOCK")
dcolum = New DataColumn("Product ID", GetType(Int32))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Name", GetType(String))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Category", GetType(String))
dtable.columns.Add(dcolum)
dcolum = New DataColumn("Product Price", GetType(Decimal))
dtable.columns.Add(dcolum)

drow = New DataRow
drow("Product ID") = 23
drow("Product Name") = "Chithra"
drow("Product Category") = "Magazine"
drow("Product Price") = 50
dtable.rows.add(drow)

For Each drow In dtable.rows
For Each dcolum In dtable.columns
Response.Write(drow(dcolum))
Next
Next
End Sub
End Class

Thanks in advance
 
M

Milosz Skalecki [MCAD]

Howdy,

Seems you accidently removed reference to System.Data assembly. Make sure
assembly "System.Data" appears on the list of references (ssems you're
working with ASP.NET 1.1 so it should be visible under the
project->references, if you're using ASP.NET right click on website->property
pages)

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,991
Messages
2,570,217
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top