Databinding programmatically

  • Thread starter Thread starter Tor Inge Rislaa
  • Start date Start date
T

Tor Inge Rislaa

Databinding programmatically



In my webform I have the code below in the form_load procedure.

On the webform I have a GridView control. My question is simply how to bind
the GridView to the datasource in the code programatically.



Dim cnn As OleDbConnection

Dim strConnection As String



strConnection = "Provider=sqloledb;Data Source=myServer;Initial
Catalog=Intranett;;Persist Security Info=True;User
ID=sa;Password=myPassword"



cnn = New OleDbConnection

cnn.ConnectionString = strConnection



Dim myDataSet As DataSet

myDataSet = New DataSet("Artikler")



Dim myDataAdapter As OleDbDataAdapter

myDataAdapter = New OleDbDataAdapter("", cnn)



Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("Select * from Artikler")



myDataAdapter.SelectCommand = CommandObject

myDataAdapter.SelectCommand.Connection = cnn



myDataAdapter.Fill(myDataSet, "Artikler")









TIRislaa
 
Are you asking "why isn't my code working?".

I don't see a "CommandObject" in your sample code:

myDataAdapter.SelectCommand = CommandObject

shoudn't that be

myDataAdapter.SelectCommand = MyCommand



Peter
 
Yes you have right it should have been myCommand, but my question is not why
my code isn't working. I have a code that I know is OK (by testing the
rows.count ) but I am simply asking how to bind the data to the gridview on
the webform by code (not by the wizard used when dragging the gridview to
the form)
 
Back
Top