Probelm connection to database asp.net
Posted on 2006-03-30
I am trying to connect to database in asp.net form by coding my connection rather than using the asp.net in built components. here is my code.
Dim myconnection As OleDbConnection
Dim mycommand As OleDbDataAdapter
Dim mydataset As DataSet
Dim mytable As DataTable
Dim sql As String
Dim loop1, numrows As Integer
'Me.OleDbCommand1.CommandText = "SELECT brand_name FROM brand"
'drpbrand_nm.DataSource = DataSet1
'brand = drpbrand_nm.SelectedValue
sql = " select brand_name from brand"
mycommand = New OleDbDataAdapter(sql, conn)
mydataset = New DataSet
drpbrand_nm.DataSource = mydataset
drpbrand_nm.DataBind() -------------------------------> There is a drop down on my form which I am trying to populate using this code
numrows = mytable.Rows.Count-----------------------> Errors out over here . See the error at bottom
For loop1 = 0 To numrows - 1
drpbrand_nm.SelectedValue = mytable.Rows(loop1).Item("brand_name")
Here is the error I get. "Object reference not set to an instance of an object". So it sounds like it is not connecting to the table. until now I was used to setting up connections using dataadapters, dataset and command from asp.net in built components. But for this project I am not allowed to use those . So please help me.