473,804 Members | 3,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding programmaticall y

Databinding programmaticall y

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=sqlol edb;Data Source=myServer ;Initial
Catalog=Intrane tt;;Persist Security Info=True;User
ID=sa;Password= myPassword"

cnn = New OleDbConnection

cnn.ConnectionS tring = strConnection

Dim myDataSet As DataSet

myDataSet = New DataSet("Artikl er")

Dim myDataAdapter As OleDbDataAdapte r

myDataAdapter = New OleDbDataAdapte r("", cnn)

Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("S elect * from Artikler")

myDataAdapter.S electCommand = CommandObject

myDataAdapter.S electCommand.Co nnection = cnn

myDataAdapter.F ill(myDataSet, "Artikler")



TIRislaa


Nov 15 '06 #1
4 4700
Are you asking "why isn't my code working?".

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

myDataAdapter.S electCommand = CommandObject

shoudn't that be

myDataAdapter.S electCommand = MyCommand

Peter

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


"Tor Inge Rislaa" wrote:
Databinding programmaticall y

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=sqlol edb;Data Source=myServer ;Initial
Catalog=Intrane tt;;Persist Security Info=True;User
ID=sa;Password= myPassword"

cnn = New OleDbConnection

cnn.ConnectionS tring = strConnection

Dim myDataSet As DataSet

myDataSet = New DataSet("Artikl er")

Dim myDataAdapter As OleDbDataAdapte r

myDataAdapter = New OleDbDataAdapte r("", cnn)

Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("S elect * from Artikler")

myDataAdapter.S electCommand = CommandObject

myDataAdapter.S electCommand.Co nnection = cnn

myDataAdapter.F ill(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*******@yaho o.nospammin.com skrev i melding
news:99******** *************** ***********@mic rosoft.com...
Are you asking "why isn't my code working?".

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

myDataAdapter.S electCommand = CommandObject

shoudn't that be

myDataAdapter.S electCommand = MyCommand

Peter

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


"Tor Inge Rislaa" wrote:
>Databinding programmaticall y

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

strConnectio n = "Provider=sqlol edb;Data Source=myServer ;Initial
Catalog=Intran ett;;Persist Security Info=True;User
ID=sa;Password =myPassword"

cnn = New OleDbConnection

cnn.Connection String = strConnection

Dim myDataSet As DataSet

myDataSet = New DataSet("Artikl er")

Dim myDataAdapter As OleDbDataAdapte r

myDataAdapte r = New OleDbDataAdapte r("", cnn)

Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("S elect * from Artikler")

myDataAdapter. SelectCommand = CommandObject

myDataAdapter. SelectCommand.C onnection = cnn

myDataAdapter. Fill(myDataSet, "Artikler")



TIRislaa



Nov 15 '06 #3
MyGridView.Data Source =myDataSet.Tabl es(0)
MyGridView.Data Bind()

This will bind with All columns. If you have set ItemTemplates and turned
off "Autogenera te 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*******@yaho o.nospammin.com skrev i melding
news:99******** *************** ***********@mic rosoft.com...
Are you asking "why isn't my code working?".

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

myDataAdapter.S electCommand = CommandObject

shoudn't that be

myDataAdapter.S electCommand = MyCommand

Peter

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


"Tor Inge Rislaa" wrote:
Databinding programmaticall y

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=sqlol edb;Data Source=myServer ;Initial
Catalog=Intrane tt;;Persist Security Info=True;User
ID=sa;Password= myPassword"

cnn = New OleDbConnection

cnn.ConnectionS tring = strConnection

Dim myDataSet As DataSet

myDataSet = New DataSet("Artikl er")

Dim myDataAdapter As OleDbDataAdapte r

myDataAdapter = New OleDbDataAdapte r("", cnn)

Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("S elect * from Artikler")

myDataAdapter.S electCommand = CommandObject

myDataAdapter.S electCommand.Co nnection = cnn

myDataAdapter.F ill(myDataSet, "Artikler")



TIRislaa




Nov 15 '06 #4
Thank you very much!

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com skrev i melding
news:40******** *************** ***********@mic rosoft.com...
MyGridView.Data Source =myDataSet.Tabl es(0)
MyGridView.Data Bind()

This will bind with All columns. If you have set ItemTemplates and turned
off "Autogenera te 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*******@yaho o.nospammin.com skrev i melding
news:99******* *************** ************@mi crosoft.com...
Are you asking "why isn't my code working?".

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

myDataAdapter.S electCommand = CommandObject

shoudn't that be

myDataAdapter.S electCommand = MyCommand

Peter

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


"Tor Inge Rislaa" wrote:

Databinding programmaticall y

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

strConnectio n = "Provider=sqlol edb;Data Source=myServer ;Initial
Catalog=Intran ett;;Persist Security Info=True;User
ID=sa;Password =myPassword"

cnn = New OleDbConnection

cnn.Connection String = strConnection

Dim myDataSet As DataSet

myDataSet = New DataSet("Artikl er")

Dim myDataAdapter As OleDbDataAdapte r

myDataAdapte r = New OleDbDataAdapte r("", cnn)

Dim myCommand As OleDbCommand

myCommand = New OleDbCommand("S elect * from Artikler")

myDataAdapter. SelectCommand = CommandObject

myDataAdapter. SelectCommand.C onnection = 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
3650
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
3872
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 with that stuff... However, as somebody out there probably knows, programmatically setting the DateTimePicker.Value property to a new VALUE does NOT in itself constitute a CHANGE to
0
5431
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 "ctlFirstName", and it's bound to the "FirstName" property of "Person". Why doesn't the following work? myForm.Show(); Person p = new Person();
4
1326
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 demand more. Usually you would also like to bind the SelectedValue to something else. Common scenario: You have an ADDRESS table with a foreign key to a STATE table. You join on an integer or uniqueidentifier key value, but the STATE table is what...
8
2189
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 answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
1
1829
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 value is not saved to database, if i edit this field manually by the keyboard it is updated correctly. here's my code, the Q_ID textbox is the filed belongs to HEADERBindingSource binding source, i try to set it by the value of newQ_id, anyone can tell...
1
7324
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 implements ITemplate and repopulate the Template properters of TemplateField in OnInit. And I am DataBinding by getting a DataTable from my db provider class in Page_Load event. When I databind programmatically in the Page_Load, the data displays in...
1
6891
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 MyClass.MyID property gets updated when the focus leaves the combobox - not when you actually select a new item from the drdop down list. I would have expected this code to solve the problem, but it didn't:
0
5028
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. I have discovered that using gridView.Columns.Remove(...) causes the gridView OnRowCommand to quit functioning for any columns that remain in the grid. (MS Please look into this, obviously a bug). So Ive been looking at other ways to hide the...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.