Object reference not set to an instance of an object.

Rani

Well-known member
Joined
Nov 19, 2005
Messages
71
Programming Experience
Beginner
This is the error i get "Object reference not set to an instance of an object. "
when i try the pc of code below. I get the error at this line"Dim dr As Data.DataRow = ds.Tables("countries").NewRow"


Dim con As New SqlConnection(Application("connection"))
Dim sql As String = "select * from countries"
Dim ds As New DataSet
Dim da As New SqlDataAdapter(sql, con)
da.Fill(ds)
Dim test As String = ds.GetXml
Dim dr As Data.DataRow = ds.Tables("countries").NewRow
dr.Item("country") = "---Please select a country---"
ds.Tables("countriesy").Rows.InsertAt(dr, 0)
Me.ddlcountry.DataSource = ds
Me.ddlcountry.DataTextField = "country"
Me.ddlcountry.DataValueField = "country_id"
Me.ddlcountry.DataBind()
ds =
Nothing

Thanks for your help
 
When you filled ds.... you didn't specify a name... therefore Tables("contries") does not exist.... include the table name when you do the Fill (.Fill(ds, "countries")) or use .Tables(0) ...

-tg
 
Back
Top