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
-
-
Public Class Form1
-
Inherits System.Windows.Forms.Form
-
-
Dim CONNECTION_STRING As String = Connection()
-
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Dim Connection As New SqlClient.SqlConnection(CONNECTION_STRING)
-
-
Dim ds As New DataSet
-
-
Dim sql As String = "SELECT * FROM tblname"
-
-
Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, Connection)
-
-
Try
-
da.Fill(ds, "tblname")
-
Finally
-
da.Dispose()
-
End Try
-
Me.TextBox1.DataBindings.Add("Text", ds, "firstname")
-
Me.TextBox1.DataBindings.Add("Text", ds, "lastname")
-
-
End Sub
-
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.
3 22103
Me.TextBox1.Dat aBindings.Add(" Text", ds.Tables("tbln ame"), "firstname" )
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: -
TextBox1.Text = ds.Tables(0).Rows(index).Item("firstname").ToString
-
TextBox2.Text = ds.Tables(0).Rows(index).Item("lastname").ToString
-
In fact this way also works but i am not sure why is the difference. -
TextBox1.DataBindings.Add("Text", ds.Tables(0), "firstname")
-
TextBox2.DataBindings.Add("Text", ds.Tables(0), "lastname")
-
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 Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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.
|
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...
|
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...
| |
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"
|
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.
|
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#.
|
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,...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |