Dear Friends,
I am building an application in ASP.net with SQL
server as backend, which contains a Master/Detail
relationship screen. The requirement is for inserting
many rows of data against one row of master data. I
would like to develop a screen where a user can make
as many rows of entries as needed (for ex. for one
Author, there can be many Titles and related details)
in the detail area. If a db grid is used for this, I
dont want to display any data in the grid as I am not
interested in viewing anything and also I don't want
to burden the form with lots of data.
The below is the lines of code I used to achieve this
task.
Private Sub BindGrid()
Dim ds As DataSet
If Session("data") Is Nothing Then
CreateDataSet()
End If
ds = CType(Session("data"), DataSet)
DataGrid1.DataSource = ds
DataGrid1.DataMember = "orderdetails"
DataGrid1.DataBind()
End Sub
Private Sub CreateDataSet()
Dim ds As DataSet = New DataSet
Dim cnn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("connstr"))
Dim da As SqlDataAdapter = New
SqlDataAdapter("select * from orderdetails where 1=2",
cnn)
da.Fill(ds, "orderdetails")
Dim colid As DataColumn = New DataColumn
colid.ColumnName = "id"
colid.AutoIncrement = True
colid.AutoIncrementSeed = 1
ds.Tables(0).Columns.Add(colid)
End Sub
Private Sub btnAddProd_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
btnAddProd.Click
Dim ds As DataSet = CType(Session("data"),
DataSet)
Dim row As DataRow = ds.Tables(0).NewRow
ds.Tables(0).Rows.Add(row)
BindGrid()
End Sub
When I click the btnAddProd_Click then it is giving
error.
Object reference not set to an instance of an object.
on this line.
Dim row As DataRow = ds.Tables(0).NewRow
Also my the value for ds showing = nothing in debug.
Please help me this is very urgen.
Thanks in Advance
Parvez Khan
__________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
.