473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Databinding programmatically

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


Nov 15 '06 #1
4 4679
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:
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


Nov 15 '06 #2
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)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comskrev i melding
news:99**********************************@microsof t.com...
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:
>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



Nov 15 '06 #3
MyGridView.DataSource =myDataSet.Tables(0)
MyGridView.DataBind()

This will bind with All columns. If you have set ItemTemplates and turned
off "Autogenerate Columns", then it will bind to the specified columns you've
defined ItemTemplates for.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:
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)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comskrev i melding
news:99**********************************@microsof t.com...
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:
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




Nov 15 '06 #4
Thank you very much!

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comskrev i melding
news:40**********************************@microsof t.com...
MyGridView.DataSource =myDataSet.Tables(0)
MyGridView.DataBind()

This will bind with All columns. If you have set ItemTemplates and turned
off "Autogenerate Columns", then it will bind to the specified columns
you've
defined ItemTemplates for.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:
>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)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comskrev i melding
news:99**********************************@microso ft.com...
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tor Inge Rislaa" wrote:

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





Nov 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
0
by: Patrick B | last post by:
I'm wondering about the mechanics of databinding. Say that a textbox is bound to a property of a business object. The business object is a "Person". The control is a textbox called...
4
by: JV | last post by:
It's easy to databind a listbox or dropdownlist if all you want is to fill it with a list of values. There are plenty of examples in the online help. Unfortunately, real world applications...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
1
by: m_mohanna | last post by:
I've problem with databinding in vb.net The problem that i'm trying to set a text field of the databinding programmatically during runtime, the change appears on the form, but after save the new...
1
by: Mark Stafford | last post by:
I am attempting to use a DetailsView control to view some data where the fields returned by the database are determined at runtime. I create the TemplateFields on the fly using a class that...
1
by: Johnny Jörgensen | last post by:
I've got a combobox where the SelectedValue property is bound to a class property by a code like this: MyComboBox.DataBindings.Add("SelectedValue", MyClass , "MyID"); My problem is that the...
0
by: =?Utf-8?B?SlA=?= | last post by:
I have several data sources that use the same gridView. I need to remove columns from the gridview at run time where the DataBind.Eval statements dont apply to the query currently using the grid. ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.