473,653 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bind data to textboxes

I'm calling a component to get my data. The component is returning a
dataset. I need to populate text boxes on my aspx page with the data within
the datalist.
Where can I find an example that does this?

Here is the code i'm using and i'm gettting an error:
code:

Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand
Dim da As Oracle.DataAcce ss.Client.Oracl eDataReader
da = cmd.ExecuteRead er(CommandBehav ior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToS tring
End If
Catch ex As Exception
lblError.Text = "Error: " & ex.Message
End Try

error:

Object reference not set to an instance of an object.
what am i doing wrong? I don't want to use a datalist i just want to
populate the textboxes

Nov 19 '05 #1
12 2629
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
I'm calling a component to get my data. The component is returning a
dataset. I need to populate text boxes on my aspx page with the data
within
the datalist.
Where can I find an example that does this?

Here is the code i'm using and i'm gettting an error:
code:

Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand


You never created an instance. Try:

Dim cmd As New Oracle.DataAcce ss.Client.Oracl eCommand

John Saunders
Nov 19 '05 #2
I have this now:
Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand
Dim da As Oracle.DataAcce ss.Client.Oracl eDataReader
cmd = new Oracle.DataAcce ss.Client.Oracl eCommand
da = cmd.ExecuteRead er(CommandBehav ior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToS tring
End If
Catch ex As Exception
lblError.Text = "Error: " & ex.Message
End Try

and now i'm getting this error:
Error: Operation is not valid due to the current state of the object.

"John Saunders" wrote:
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
I'm calling a component to get my data. The component is returning a
dataset. I need to populate text boxes on my aspx page with the data
within
the datalist.
Where can I find an example that does this?

Here is the code i'm using and i'm gettting an error:
code:

Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand


You never created an instance. Try:

Dim cmd As New Oracle.DataAcce ss.Client.Oracl eCommand

John Saunders

Nov 19 '05 #3
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.com...
I have this now:
Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand
Dim da As Oracle.DataAcce ss.Client.Oracl eDataReader
cmd = new Oracle.DataAcce ss.Client.Oracl eCommand
da = cmd.ExecuteRead er(CommandBehav ior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToS tring
End If
Catch ex As Exception
lblError.Text = "Error: " & ex.Message
End Try

and now i'm getting this error:
Error: Operation is not valid due to the current state of the object.


Don't you need an open OracleConnectio n in cmd.Connection?

John Saunders
Nov 19 '05 #4
the dbConn.function name has the connection string in it.

the code works when i want to populate a datagrid or datalist, its when i
need to populate text boxes it breaks. I can also create a data set from the
function call and write out the dataset to the screen in XML form. I'm
missing something to populate text boxes with this

"John Saunders" wrote:
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.com...
I have this now:
Try
dbConn.GetCarIn formation(CarID )
Dim cmd As Oracle.DataAcce ss.Client.Oracl eCommand
Dim da As Oracle.DataAcce ss.Client.Oracl eDataReader
cmd = new Oracle.DataAcce ss.Client.Oracl eCommand
da = cmd.ExecuteRead er(CommandBehav ior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToS tring
End If
Catch ex As Exception
lblError.Text = "Error: " & ex.Message
End Try

and now i'm getting this error:
Error: Operation is not valid due to the current state of the object.


Don't you need an open OracleConnectio n in cmd.Connection?

John Saunders

Nov 19 '05 #5
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:C8******** *************** ***********@mic rosoft.com...
the dbConn.function name has the connection string in it.


That may be, but you need cmd.Connection to be set to an open connection.

John Saunders
Nov 19 '05 #6
In this scenario then how would i do that?

would it be
dim conn as new oracleconnectio n = dbConn.Function or another way?
"John Saunders" wrote:
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:C8******** *************** ***********@mic rosoft.com...
the dbConn.function name has the connection string in it.


That may be, but you need cmd.Connection to be set to an open connection.

John Saunders

Nov 19 '05 #7
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:0E******** *************** ***********@mic rosoft.com...
In this scenario then how would i do that?

would it be
dim conn as new oracleconnectio n = dbConn.Function or another way?


You'll have to talk to your people to ask them where to get the connection
string from. You said that there was a connection inside of
dbConn.somethin g. But once you get an OracleConnectio n, you have to set
cmd.Connection to that connection, before executing the command with
cmd.Execute<wha tever>.

Setting the Connection is how the OracleCommand object knows which database
to execute the command on.

John Saunders
Nov 19 '05 #8
I wrote both pieces the component i'm using and the aspx app i'm writing.
Why do i need to have the connection string in the aspx (code behind)if the
component is already has the connection string in it and works?

I don't see why databinding textboxes in asp.net is hell like this. the old
way it was just using <%=dataitem%> and i was done. It appears in .NET is
like going through and act of congress to pop textboxes in .NET

If i'm calling a function that already populates a datagrid and has the
connection string in it, why do i need to create another connection string to
populate textboxes from the same function. I'm lost on this one.
"John Saunders" wrote:
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:0E******** *************** ***********@mic rosoft.com...
In this scenario then how would i do that?

would it be
dim conn as new oracleconnectio n = dbConn.Function or another way?


You'll have to talk to your people to ask them where to get the connection
string from. You said that there was a connection inside of
dbConn.somethin g. But once you get an OracleConnectio n, you have to set
cmd.Connection to that connection, before executing the command with
cmd.Execute<wha tever>.

Setting the Connection is how the OracleCommand object knows which database
to execute the command on.

John Saunders

Nov 19 '05 #9
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
I wrote both pieces the component i'm using and the aspx app i'm writing.
Why do i need to have the connection string in the aspx (code behind)if
the
component is already has the connection string in it and works?

I don't see why databinding textboxes in asp.net is hell like this. the
old
way it was just using <%=dataitem%> and i was done. It appears in .NET is
like going through and act of congress to pop textboxes in .NET

If i'm calling a function that already populates a datagrid and has the
connection string in it, why do i need to create another connection string
to
populate textboxes from the same function. I'm lost on this one.


I haven't been discussing connection strings, I've been discussing
connections.

I think part of this is bad design. You've got a function that populates the
data grid with some data, then you need to use some of that data outside of
the function, in order to populate some text boxes. Do I have that right?

If so, you should encapsulate some of this into a class. The class would
have a method which would populate a DataSet object with all of the data you
need. It would then expose the DataSet as a read-only property of itself.
You could use the exposed DataSet to populate the DataGrid and also to
populate the text boxes:

Public Class MyDataLayer
Private _dataSet As New DataSet
Private _connectionStri ng As String
Private _connection as OracleConnectio n

Public Sub New
_connectionStri ng = Configuration.A ppSettings("con nectionString")
End Sub

Public Sub LoadData(parent Id As Integer)
_connection.Ope n
Dim cmdFillParent As New OracleCommand(" Select * from Parent where
Id=@Id", _connection)
cmdFillParent.P arameters("@Id" ).Value = parentId
Dim da As New OracleDataAdapt er(cmdFillParen t)
da.Fill(_dataSe t, "Parent")
'
Dim cmdFillChildren As New OracleCommand(" Select * from Child where
ParentId=@Id", _connection)
cmdFillChildren .Parameters("@I d").Value = parentId
da = New OracleDataAdapt er(cmdFillChild ren)
da.Fill(_dataSe t, "Child")
End Sub

Public ReadOnly Property Data As DataSet
Get
Return _dataSet
End Get
End Property
End Class
In your .aspx.vb:
Protected _dataLayer As New MyDataLayer
Public Sub Page_Load(sende r As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim id As Integer = Integer.Parse(R equest("Id"))
_dataLayer.Load Data(id)
'
DataBind()
End If
End Sub

In your .aspx page:

<asp:TextBox runat="server" id="txtName"><% #
_dataLayer.Data .Tables("Parent ").Rows(0)("Nam e") %></asp:TextBox>
....
<asp:DataGrid runat="server" id="grdChildren " DataSource="<%#
_dataLayer.Data %>", DataMember="Chi ld">
....
</asp:DataGrid>
How's that? You only maintain the connection and the connection string in
one place, but you can use the data in multiple places. And if you need to
do something else to the data, you've still got the dataset and the
connection to the database inside of the MyDataLayer class, so you can just
add, for instance, an UpdateParent method.

John Saunders
Nov 19 '05 #10

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

Similar topics

6
3317
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on different rows in the datagrid, the textbox content doesn't change to reflect the change. How can I address this? Also, If the user change the text in the textbox then how do I refesh the display in the datagrid to reflect the changes? ...
0
1398
by: Steve | last post by:
Hi I have a db with 2 tables that I want to bind to a grid depending on a selection in a Dropdownlist Also I want to be able to select a row from the gris to fill some textboxes. The databases are static in that they will not be updated they are just for viewing I have everything working but not to perfection
4
9815
by: Rich | last post by:
Hello, I have successfully created an oledbconnection (oleconn) to an Access mdb file along with an oleaDBdapter (oleda) and a dataset (ds1). If I loop through the dataset For i = 1 to 10 For Each col in ds1.Tables(0).Columns... Console.Write col....(0,i), ...(1,i)...(2,i) Next
0
1556
by: uwe.braunholz | last post by:
Hello, I want to enable/disable some Textboxes by a property of a derived BindingSource-class. This is what i got so far: ---- class myBindingSource : BindingSource { public object mxtest = false; public EventHandler testChanged;
2
5699
by: Mikus Sleiners | last post by:
I have a control - textBox1 that is binded to objects propery - "Currency" and another control - textBox2 (read only) that is also binded to same propery. Now, i have a situation where textbox1 control does NOT refresh it's display according to value set to underlying propery while at the same time textBox2 does refresh accordingly. Both textboxes ar located on the same form and there are no diferences in their bindings.
2
5930
by: chandana Devabhaktuni | last post by:
Hello and Hi to everyone, This is chandana, i have a doubt which i am mentioning here. We can retrive or bind data to datagrid from database(sql server) and also we can insert data and can make modifications. In the same way how to retrive or bind data from database(sql server) to textboxes and to other controls that are placed in a table or placed simply on a form or page and how to make modificatons like...
1
3365
by: adolph | last post by:
I wrote an access2000 database for a POS system. In it is a sales form with a a subform showing the items being purchased. The main form is unbound. It uses a class to hold the main form data and to read/write to the sales table. What I'm having trouble with is what to use as the 'Recordsource' for the subform (Items being sold). I do not want to bind the subform directly to the itemsSold table. What I would like to do is create a...
0
1611
by: =?Utf-8?B?Q2hyaXN0aWFuIEJhaG5zZW4=?= | last post by:
Is it possible to bind a data access page textbox controlsource property at run time? I've tried using the BeforeInitialBind event to set the controlsource for textboxes, using syntax like txtTwelfthMonth.ControlSource = temp but I get the
3
22041
by: raamay | last post by:
I have a module where i have specified the connection string as below: Public Function Connection() As String Return "Data Source=192.168.0.1,1433;Network Library=DBMSSOCN;Initial Catalog=test;User ID=sa;Password=123456" End Function Then i have a form which has two textboxes. What i am trying to do is bind the two textboxes to a dataset in the following way: Imports System.Data.SqlClient
0
8370
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
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7302
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
6160
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
4147
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
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
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.