|
-
Aug 23rd, 2004, 11:39 AM
#1
Thread Starter
PowerPoster
textboxes and fill
hi there.
instead of using a dataset/datalist, is it possible to fill TEXTBOXES instead?
basically i have a button, this button issues or gets the record ID.
when user clicks on it, i want it to get other details relating to that record. what i then want it to do is simply get the rest of the details and put them textboxes
any ideas?
-
Aug 23rd, 2004, 04:14 PM
#2
One way would be to read from a database and assign the values straight to the text property of the boxes
VB Code:
txtBox.Text = dataSource("name")
Though that could get a bit out of hand if you had a lot of textboxes.
-
Aug 23rd, 2004, 05:00 PM
#3
Thread Starter
PowerPoster
could u explain a bit more please?
ok so i have the code for the connection...then what?
-
Aug 23rd, 2004, 06:16 PM
#4
I'm off now but here's an example from an old project you can look at for now.
VB Code:
Dim cmdSelect As SqlCommand
Dim dtrReader As SqlDataReader
'Create SQL command and add parameters
cmdSelect = New SqlCommand("up_parm_sel_player", objConn)
cmdSelect.CommandType = CommandType.StoredProcedure
cmdSelect.Parameters.Add("@player_id", intPlayerID)
dtrReader = cmdSelect.ExecuteReader(CommandBehavior.SingleRow)
While dtrReader.Read
txtEmail.text = dtrReader("email_address")
txtFirst.text = dtrReader("first_name")
txtLast.text = dtrReader("Last_name")
End While
-
Aug 24th, 2004, 03:36 AM
#5
Thread Starter
PowerPoster
hey thanks for that The other thing is, this table uses joins, i have the SQL Statement to do this but exactly where do i put this in the code with the one above?
do i add it and execute it then do the stuff as above? or what?
-
Aug 24th, 2004, 07:41 AM
#6
VB Code:
cmdSelect = New SqlCommand("up_parm_sel_player", objConn)
"up_parm_sel_player" in this case is a stored procedure and this is where you'd put your SQL string.
-
Aug 24th, 2004, 07:51 AM
#7
Thread Starter
PowerPoster
thanks 
ok it seems to do it but whenever there is a DBNULL value it cant assign it to a string (textbox)
what should i do in this situation?
Last edited by Techno; Aug 24th, 2004 at 07:56 AM.
-
Aug 24th, 2004, 08:58 AM
#8
I wonder how many charact
IF you don't want to use a dataset, datatable, or a datalist that binds to the datareader... then you could just populate an object array.
VB Code:
dtr = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)
Dim obj(dtr.FieldCount-1) As Object
While dtr.Read
If dtr("keyColumn") = passedKeyArgument Then
obj = dtr.GetValues()
Exit While
End If
End While
'close the reader
dtr.Close()
'now obj is an array of values from the datareader
'you can test for DBNull's easily enough
If Not obj(1) is DBNull.Value Then TextBox1.Text = DirectCast(obj(1),String)
'or it may be test for if Obj(1) Is Nothing, i forget
-
Aug 24th, 2004, 11:27 AM
#9
Thread Starter
PowerPoster
any other better way than an array?
-
Aug 24th, 2004, 11:35 AM
#10
It depends on exactly what you're doing and ultimately it's you're choice.
I think reading a db straight to textboxes and then writing back to the db from the same textboxes is 'ok' for a simple 'Edit details' page but it depends on your requirements.
As for the null issue when reading from the database you can just use 'If isDbnull(whatever)...' to place blank strings in your textboxes.
-
Aug 24th, 2004, 02:26 PM
#11
I wonder how many charact
You could use a enumerator to fill a dbrecord, but in reality, it works the same as an array, much like a datarow in a datatable...
What word do you feel most comfortable with?
VB Code:
Dim dr As System.Data.SqlClient.SqlDataReader
dr = sqlcommand1.ExecuteReader(CommandBehavior.CloseConnection)
Dim dbe As New System.Data.Common.DbEnumerator(dr)
Dim dbr As System.Data.Common.DbDataRecord
dbe.MoveNext()
dr.Read
dbr = dbe.Current
If not dbr(0) is dbnull.value then textbox1.text = dbr(0)
if not dbr("CompanyName") is DbNull.Value then textbox2.text= dbr("CompanyName")
dr.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|