473,386 Members | 1,610 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,386 software developers and data experts.

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.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand
Dim da As Oracle.DataAccess.Client.OracleDataReader
da = cmd.ExecuteReader(CommandBehavior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToString
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 2606
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.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.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand


You never created an instance. Try:

Dim cmd As New Oracle.DataAccess.Client.OracleCommand

John Saunders
Nov 19 '05 #2
I have this now:
Try
dbConn.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand
Dim da As Oracle.DataAccess.Client.OracleDataReader
cmd = new Oracle.DataAccess.Client.OracleCommand
da = cmd.ExecuteReader(CommandBehavior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToString
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**@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.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.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand


You never created an instance. Try:

Dim cmd As New Oracle.DataAccess.Client.OracleCommand

John Saunders

Nov 19 '05 #3
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
I have this now:
Try
dbConn.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand
Dim da As Oracle.DataAccess.Client.OracleDataReader
cmd = new Oracle.DataAccess.Client.OracleCommand
da = cmd.ExecuteReader(CommandBehavior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToString
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 OracleConnection 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**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
I have this now:
Try
dbConn.GetCarInformation(CarID)
Dim cmd As Oracle.DataAccess.Client.OracleCommand
Dim da As Oracle.DataAccess.Client.OracleDataReader
cmd = new Oracle.DataAccess.Client.OracleCommand
da = cmd.ExecuteReader(CommandBehavior.SingleRow)
If da.Read Then
txtCarName.Text = da("Model").ToString
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 OracleConnection in cmd.Connection?

John Saunders

Nov 19 '05 #5
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.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 oracleconnection = dbConn.Function or another way?
"John Saunders" wrote:
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.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**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
In this scenario then how would i do that?

would it be
dim conn as new oracleconnection = 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.something. But once you get an OracleConnection, you have to set
cmd.Connection to that connection, before executing the command with
cmd.Execute<whatever>.

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**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
In this scenario then how would i do that?

would it be
dim conn as new oracleconnection = 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.something. But once you get an OracleConnection, you have to set
cmd.Connection to that connection, before executing the command with
cmd.Execute<whatever>.

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

John Saunders

Nov 19 '05 #9
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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 _connectionString As String
Private _connection as OracleConnection

Public Sub New
_connectionString = Configuration.AppSettings("connectionString")
End Sub

Public Sub LoadData(parentId As Integer)
_connection.Open
Dim cmdFillParent As New OracleCommand("Select * from Parent where
Id=@Id", _connection)
cmdFillParent.Parameters("@Id").Value = parentId
Dim da As New OracleDataAdapter(cmdFillParent)
da.Fill(_dataSet, "Parent")
'
Dim cmdFillChildren As New OracleCommand("Select * from Child where
ParentId=@Id", _connection)
cmdFillChildren.Parameters("@Id").Value = parentId
da = New OracleDataAdapter(cmdFillChildren)
da.Fill(_dataSet, "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(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim id As Integer = Integer.Parse(Request("Id"))
_dataLayer.LoadData(id)
'
DataBind()
End If
End Sub

In your .aspx page:

<asp:TextBox runat="server" id="txtName"><%#
_dataLayer.Data.Tables("Parent").Rows(0)("Name") %></asp:TextBox>
....
<asp:DataGrid runat="server" id="grdChildren" DataSource="<%#
_dataLayer.Data %>", DataMember="Child">
....
</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
Now what you show below is not really any different then what i already have,
the only difference is that i created a Component in my project instead of a
class

"John Saunders" wrote:
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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 _connectionString As String
Private _connection as OracleConnection

Public Sub New
_connectionString = Configuration.AppSettings("connectionString")
End Sub

Public Sub LoadData(parentId As Integer)
_connection.Open
Dim cmdFillParent As New OracleCommand("Select * from Parent where
Id=@Id", _connection)
cmdFillParent.Parameters("@Id").Value = parentId
Dim da As New OracleDataAdapter(cmdFillParent)
da.Fill(_dataSet, "Parent")
'
Dim cmdFillChildren As New OracleCommand("Select * from Child where
ParentId=@Id", _connection)
cmdFillChildren.Parameters("@Id").Value = parentId
da = New OracleDataAdapter(cmdFillChildren)
da.Fill(_dataSet, "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(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim id As Integer = Integer.Parse(Request("Id"))
_dataLayer.LoadData(id)
'
DataBind()
End If
End Sub

In your .aspx page:

<asp:TextBox runat="server" id="txtName"><%#
_dataLayer.Data.Tables("Parent").Rows(0)("Name") %></asp:TextBox>
....
<asp:DataGrid runat="server" id="grdChildren" DataSource="<%#
_dataLayer.Data %>", DataMember="Child">
....
</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 #11
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
Now what you show below is not really any different then what i already
have,
the only difference is that i created a Component in my project instead of
a
class
1) A component is a class
2) If you have a component which exposes the data, then why can't you use it
to fill your textboxes?

John Saunders
"John Saunders" wrote:
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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 _connectionString As String
Private _connection as OracleConnection

Public Sub New
_connectionString = Configuration.AppSettings("connectionString")
End Sub

Public Sub LoadData(parentId As Integer)
_connection.Open
Dim cmdFillParent As New OracleCommand("Select * from Parent
where
Id=@Id", _connection)
cmdFillParent.Parameters("@Id").Value = parentId
Dim da As New OracleDataAdapter(cmdFillParent)
da.Fill(_dataSet, "Parent")
'
Dim cmdFillChildren As New OracleCommand("Select * from Child
where
ParentId=@Id", _connection)
cmdFillChildren.Parameters("@Id").Value = parentId
da = New OracleDataAdapter(cmdFillChildren)
da.Fill(_dataSet, "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(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim id As Integer = Integer.Parse(Request("Id"))
_dataLayer.LoadData(id)
'
DataBind()
End If
End Sub

In your .aspx page:

<asp:TextBox runat="server" id="txtName"><%#
_dataLayer.Data.Tables("Parent").Rows(0)("Name") %></asp:TextBox>
....
<asp:DataGrid runat="server" id="grdChildren" DataSource="<%#
_dataLayer.Data %>", DataMember="Child">
....
</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 #12
It has got nothing to do with a datalist. You have simply not
instantiated the command object.

Dim cmd As Oracle.DataAccess.Client.OracleCommand

Modify it to

Dim cmd As New Oracle.DataAccess.Client.OracleCommand

and specify the command and the connection for this object.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #13

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

Similar topics

6
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...
0
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...
4
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...
0
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 =...
2
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...
2
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...
1
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...
0
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 ...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.