473,832 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind Textbox to Dataset

107 New Member
I have a module where i have specified the connection string as below:
Expand|Select|Wrap|Line Numbers
  1. Public Function Connection() As String
  2.         Return "Data Source=192.168.0.1,1433;Network Library=DBMSSOCN;Initial Catalog=test;User ID=sa;Password=123456"
  3.     End Function
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2.  
  3. Public Class Form1
  4.     Inherits System.Windows.Forms.Form
  5.  
  6.     Dim CONNECTION_STRING As String = Connection()
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.         Dim Connection As New SqlClient.SqlConnection(CONNECTION_STRING)
  10.  
  11.         Dim ds As New DataSet
  12.  
  13.         Dim sql As String = "SELECT * FROM tblname"
  14.  
  15.         Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, Connection)
  16.  
  17.         Try
  18.             da.Fill(ds, "tblname")
  19.         Finally
  20.             da.Dispose()
  21.         End Try
  22.         Me.TextBox1.DataBindings.Add("Text", ds, "firstname")
  23.         Me.TextBox1.DataBindings.Add("Text", ds, "lastname")
  24.  
  25.     End Sub
  26.  
I get the error "Cannot bind to the property or column firstname on the DataSource. Parameter name: dataMember".

What is wrong and how can i achieve this..please direct me.
Mar 26 '09 #1
3 22103
aryanbs
42 New Member
Me.TextBox1.Dat aBindings.Add(" Text", ds.Tables("tbln ame"), "firstname" )
Mar 26 '09 #2
raamay
107 New Member
thankyou for the help but it didnt work. So i tried in the following way and it worked. But i am not sure what is the difference between the binding method and the one below:
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = ds.Tables(0).Rows(index).Item("firstname").ToString
  2. TextBox2.Text = ds.Tables(0).Rows(index).Item("lastname").ToString
  3.  
In fact this way also works but i am not sure why is the difference.
Expand|Select|Wrap|Line Numbers
  1. TextBox1.DataBindings.Add("Text", ds.Tables(0), "firstname")
  2. TextBox2.DataBindings.Add("Text", ds.Tables(0), "lastname")
  3.  
Mar 27 '09 #3
aryanbs
42 New Member
Excellant, you found the problem

ds.Tables("tbln ame") but ds.Tables(0), so 0 is the table you are binding, i thought you were also filling datatable with name tblname, its samething whether you go by table name or table index

In first case you are assigning value of certain row manually to textbox, in another one you are binding the property text to data source

Look at this link as well

http://software.techrepublic.com.com...5&promo=100511
Mar 27 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
384
by: Steve | last post by:
C# I have some combo boxes, full of lookup descriptions. When I retrieve a dataset for my record, the values that need binding to the combos are the actual record IDs that relate to these lookup descriptions. How do I bind them up in this case? Thanks Steve
4
2203
by: David P. Donahue | last post by:
When I bind a dataset to a SQL query that contains a blob field it comes back as a byte array. Is there any way to have it interpreted as a string or somehow convert it to a string? I'm using the blob field to store large amounts of text and I need to be able to interpret it as such. Regards, David P. Donahue ddonahue@ccs.neu.edu
2
9608
by: OldNewbie | last post by:
Hello All I have a textbox control. I would like this text box to automatically update to contain the currently selected item located in a listbox which is on the same form. Do I need a CurrencyManager for this? Can this be done just by manipulating the databindings properties of the textbox? If so, please do give me some hints as to the syntax I would use to fill in that field on the property panel - everything I try is rejected.
4
2582
by: John Rose | last post by:
I have one databound TextBox on a page with one button. The TextBox loads the correct SQL record data but typing a new string into the Textbox fails to change the DataSet. Any ideas? There must be some way to force the edited TextBox to update the DataSet since it appears to not be done automatically. //-------------------------------------------------------------------------- -------------------------- private void Page_Load(object...
3
17769
by: MrMike | last post by:
Hi. I have a dataset on my webform which I successfully fill by calling a Sub that occurs after the Page_Load. My question is - I have a textbox control which I need to populate with the contents of one of the Dataset columns. If I set set the binding properties using the properties window, this isn't successfull since the textbox attempts to bind at page_load, at which time the dataset is not filled. How can I use VB code to specify...
0
1453
by: rbutch | last post by:
hey guys got a question. im trying to bind a textbox "at runtime". im creating the conn string, dataset, dataAdapter etc dynamically. and it keeps erroring out. <asp:TextBox ID="txtDay1" Runat="server" TextMode='<%# A39.DataRow%>'></asp:TextBox> now i have no problem doing this if i hard code my connection string, dataadapter, dataset etc and use the method (databinder eval). <asp:TextBox ID="txtDay1" Runat="server"
17
2776
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
1
1403
by: Adam J Knight | last post by:
Hi all, I am assuming there may be a number of ways to bind a text box to a db field using c#. My current approach is: txtPostCode.Text = rdrInstitution.ToString(); Can anyone let me if there is a generally accepted method for databinding a textbox using c#.
0
9642
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
10498
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...
1
10540
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
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
7753
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
5623
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
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3970
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.