|
-
Sep 2nd, 2005, 08:51 AM
#1
Thread Starter
Fanatic Member
databind to a textbox
howde me again,
looking to databind to a textbow.
one column in my table. has anyone done this before ive had a go below but as usual, nothin happens, prob missin a line or 2, i want to do this so the data can be edited and then saved.
thanks in advance
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
loadtextboxs()
End Sub
Private Sub loadtextboxs()
'connect to database
'Dim oSQLConn As SqlConnection = New SqlConnection
oSQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=TaT;" & _
"Integrated Security=SSPI"
oSQLConn.Open()
'databind the infromation
'If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
daCompMsg.SelectCommand = New SqlCommand("SELECT confirm_msg from tb_comp_msg ", oSQLConn)
daCompMsg.Fill(dsCompMsg)
'DataGrid()
' txt_msg1.DataSource = dsCompMsg.Tables(0)
txt_msg1.DataBind()
oSQLConn.Close()
-
Sep 5th, 2005, 08:31 AM
#2
Frenzied Member
Re: databind to a textbox
As TextBoxes can only hold one value they don't have DataSource and DataBind() attributes.
Try using ExecuteScalar() on the SqlCommand object you create to return just one value and then load it into the TextBox.
Code:
Dim cmdSelect As SqlCommand
cmdSelect = New SqlCommand("SELECT confirm_msg from tb_comp_msg ", oSQLConn)
txt_msg1.Text = cmdSelect.ExecuteScalar().ToString()
Give a shout if you have any problems.
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
Sep 10th, 2005, 10:47 AM
#3
Thread Starter
Fanatic Member
Re: databind to a textbox
that code rocks
i might need it to do more though
when i get stuck ill post back here and edit my title
thanks
it works 60% of the time, all the time.
-
Sep 10th, 2005, 11:08 AM
#4
Thread Starter
Fanatic Member
Re: databind to a textbox
i want now to go a little deeper,
i want the textbox to display to the current user,
who has logged in using company code column
ie display the message where company code = current user
VB Code:
Dim cmdselect As SqlCommand
cmdselect = New SqlCommand("SELECT msg_default from tb_comp_detail ", oSQLConn)
txtDefault.Text = cmdselect.ExecuteScalar().ToString()
login done on windows forms and msg_default is in the same table as companycode
it works 60% of the time, all the time.
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
|