Databinding programmatically

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
 
G

Guest

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
 
T

Tor Inge Rislaa

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)
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top