473,785 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Big problems with data binding

I am having trouble with an app that does the following:

1. Query SQL Server and return one row
2. Bind the columns to text boxes
3. User updates info
4. User clicks update button

Questions:

1. Is data binding one direction.
2. If the user changes a value in a text box how does that value get back
to the dataset or does it?

Code is as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnectio n1.Open()
Me.SqlDataAdapt er1.Fill(Me.Ter rDataSet)
Dim dv As DataView = Me.TerrDataSet. Tables(0).Defau ltView
Me.DataBind()
Me.SqlConnectio n1.Close()
Me.Session.Add( "DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Sessio n.Item("DataSet "), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnectio n1.Open()
Try
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnectio n1.Close()
End Sub

Lloyd Sheen
Nov 18 '05 #1
3 1587
Lloyd,
Note that the internet is a stateless environment. Once the request is processed on the server and the response is sent to the client it's all over as far as the server is concerned. Apart form the session id the server doesn't remember(mainta in state) anything. Also note the response being sent back is nothing but html file in text format. There's no concept of DataGrids or DataSets in HTML.

To answer your questions:
1. Is data binding one direction.
Yes it is on the internet.
2. If the user changes a value in a text box how does that value get back to the dataset or does it?


No it will not. You have to process the form that gets posted back to the server and fill up your dataset.

HTH,
Suresh.

----- Lloyd Sheen wrote: -----

I am having trouble with an app that does the following:

1. Query SQL Server and return one row
2. Bind the columns to text boxes
3. User updates info
4. User clicks update button

Questions:

1. Is data binding one direction.
2. If the user changes a value in a text box how does that value get back
to the dataset or does it?

Code is as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnectio n1.Open()
Me.SqlDataAdapt er1.Fill(Me.Ter rDataSet)
Dim dv As DataView = Me.TerrDataSet. Tables(0).Defau ltView
Me.DataBind()
Me.SqlConnectio n1.Close()
Me.Session.Add( "DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Sessio n.Item("DataSet "), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnectio n1.Open()
Try
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnectio n1.Close()
End Sub

Lloyd Sheen

Nov 18 '05 #2
Ok, things are getting really strange. First I edit the
UpdateCommand.C ommandText of the SqlDataAdapter. Of course as soon as I do
this it renews the CommandText with incorrect information. I love this IDE.

So then to get around this I move the correct SQL to the UpdateCommand and
can see that it is correct while debugging. I am just attempting a proof of
concept using the Territories table in Northwind. I have input the values
to the parameters as in the following code:

SqlDataAdapter1 .UpdateCommand. CommandText = "UPDATE Territories SET
TerritoryDescri ption = @TerritoryDescr iption, RegionID = @RegionID WHERE
(TerritoryID = @TerritoryID)"
SqlDataAdapter1 .UpdateCommand. Parameters("@Re gionID").Value =
Me.TextBox1.Tex t
SqlDataAdapter1 .UpdateCommand. Parameters("@Te rritoryDescript ion").Value =
Me.TextBox2.Tex t
SqlDataAdapter1 .UpdateCommand. Parameters("@Te rritoryID").Val ue =
Me.TextBox3.Tex t
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)

This command give me the following error:

Violation of PRIMARY KEY constraint 'PK_Territories '. Cannot insert
duplicate key in object 'Territories'.

I am updating not inserting and the update command does not update the
primary key so I have no idea what is going on. The one thing I know is
that the SqlDataAdapter is pretty useless in this case since it has no idea
how to create good SQL for updates for tables that have a primary key. And
changing the SQL is a useless operation in the designer since it seems that
the data adapter will use whatever it wants not what is entered for the
UpdateCommand.

Lloyd Sheen

"Suresh" <an*******@disc ussions.microso ft.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Lloyd,
Note that the internet is a stateless environment. Once the request is processed on the server and the response is sent to the client it's all over
as far as the server is concerned. Apart form the session id the server
doesn't remember(mainta in state) anything. Also note the response being sen
t back is nothing but html file in text format. There's no concept of
DataGrids or DataSets in HTML.
To answer your questions:
1. Is data binding one direction.
Yes it is on the internet.
2. If the user changes a value in a text box how does that value get

back to the dataset or does it?
No it will not. You have to process the form that gets posted back to the server and fill up your dataset.
HTH,
Suresh.

----- Lloyd Sheen wrote: -----

I am having trouble with an app that does the following:

1. Query SQL Server and return one row
2. Bind the columns to text boxes
3. User updates info
4. User clicks update button

Questions:

1. Is data binding one direction.
2. If the user changes a value in a text box how does that value get back to the dataset or does it?

Code is as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnectio n1.Open()
Me.SqlDataAdapt er1.Fill(Me.Ter rDataSet)
Dim dv As DataView = Me.TerrDataSet. Tables(0).Defau ltView
Me.DataBind()
Me.SqlConnectio n1.Close()
Me.Session.Add( "DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Sessio n.Item("DataSet "), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnectio n1.Open()
Try
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnectio n1.Close()
End Sub

Lloyd Sheen

Nov 18 '05 #3
And the fun continues.

I change to use a SqlCommand. Used the IDE to generate the statement which
is copied from the designer as :

UPDATE Territories SET TerritoryDescri ption = @TerritoryDescr iption,
RegionID = @RegionID WHERE (TerritoryID = @TerritoryID)

Now when I am debugging as soon as I get to the first line using the
Sq1Command the text is now:
UPDATE Territories SET TerritoryID =, TerritoryDescri ption =
@TerritoryDescr iption, RegionID = @RegionID WHERE (TerritoryID =
@TerritoryID)

So what is going on?????

It seems to have some idea that the PK for the table is around but that text
at the beginning with the TerritoryID=, comes from some magic place.

I have no reinstalled VS2003 4 times. If this is the best it can do, please
MS give us a fix.

Lloyd Sheen

"Lloyd Sheen" <sq************ *******@tostops pamhotmail.com> wrote in message
news:SG******** *************@n ews04.bloor.is. net.cable.roger s.com...
Ok, things are getting really strange. First I edit the
UpdateCommand.C ommandText of the SqlDataAdapter. Of course as soon as I do this it renews the CommandText with incorrect information. I love this IDE.
So then to get around this I move the correct SQL to the UpdateCommand and
can see that it is correct while debugging. I am just attempting a proof of concept using the Territories table in Northwind. I have input the values
to the parameters as in the following code:

SqlDataAdapter1 .UpdateCommand. CommandText = "UPDATE Territories SET
TerritoryDescri ption = @TerritoryDescr iption, RegionID = @RegionID WHERE
(TerritoryID = @TerritoryID)"
SqlDataAdapter1 .UpdateCommand. Parameters("@Re gionID").Value =
Me.TextBox1.Tex t
SqlDataAdapter1 .UpdateCommand. Parameters("@Te rritoryDescript ion").Value = Me.TextBox2.Tex t
SqlDataAdapter1 .UpdateCommand. Parameters("@Te rritoryID").Val ue =
Me.TextBox3.Tex t
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)

This command give me the following error:

Violation of PRIMARY KEY constraint 'PK_Territories '. Cannot insert
duplicate key in object 'Territories'.

I am updating not inserting and the update command does not update the
primary key so I have no idea what is going on. The one thing I know is
that the SqlDataAdapter is pretty useless in this case since it has no idea how to create good SQL for updates for tables that have a primary key. And changing the SQL is a useless operation in the designer since it seems that the data adapter will use whatever it wants not what is entered for the
UpdateCommand.

Lloyd Sheen

"Suresh" <an*******@disc ussions.microso ft.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Lloyd,
Note that the internet is a stateless environment. Once the request is processed on the server and the response is sent to the client it's all

over as far as the server is concerned. Apart form the session id the server
doesn't remember(mainta in state) anything. Also note the response being sen t back is nothing but html file in text format. There's no concept of
DataGrids or DataSets in HTML.

To answer your questions:
1. Is data binding one direction.
Yes it is on the internet.
2. If the user changes a value in a text box how does that value get back to the dataset or does it?

No it will not. You have to process the form that gets posted back to

the server and fill up your dataset.

HTH,
Suresh.

----- Lloyd Sheen wrote: -----

I am having trouble with an app that does the following:

1. Query SQL Server and return one row
2. Bind the columns to text boxes
3. User updates info
4. User clicks update button

Questions:

1. Is data binding one direction.
2. If the user changes a value in a text box how does that value

get back
to the dataset or does it?

Code is as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnectio n1.Open()
Me.SqlDataAdapt er1.Fill(Me.Ter rDataSet)
Dim dv As DataView = Me.TerrDataSet. Tables(0).Defau ltView
Me.DataBind()
Me.SqlConnectio n1.Close()
Me.Session.Add( "DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Sessio n.Item("DataSet "), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e

As System.EventArg s) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnectio n1.Open()
Try
picnt = Me.SqlDataAdapt er1.Update(Me.T errDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnectio n1.Close()
End Sub

Lloyd Sheen


Nov 18 '05 #4

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

Similar topics

0
2350
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a visual representation of data. Two types of data binding are available for Windows Forms: Simple Data Binding and Complex Data Binding. Simple data binding allows you to bind one data element to a control. In many situations you want to display...
6
1683
by: Ruy Castelli | last post by:
Hello, I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers. When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it...
0
5676
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
2
1339
by: Lori Markle via .NET 247 | last post by:
Hi, I already posted this but can't find it anywhere! I'm having a problem that seems very simple. I'm trying to updatea db and am getting stuck on the data binding of a textbox. Iget a "Cannot bind to property or column permitnumber onDataSource" OR if I use ("text", ds, "permits.permitnumber")nothing happens except that a permit number that already existsshows up in the textbox. Do I have something in the wrong order?HEre is my code: Dim...
19
2347
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
0
2216
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue correctly, posting to the wrong forum, or committing some other sort of faux pas. My team is developing a Windows Forms application using VS 2005 with SQL Server 2005 on the back end and we're having a problem using ComboBoxes data bound to lookup...
14
14659
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control so I get the ObjectDataSource. No problem ..... ObjectDataSource src = .... //is ok i have it
9
4026
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New DataTable("SliceInfo") Dim tblSliceRatings As New DataTable("SliceRatings") '.... All the adding datacolumns, datarows, etc. goes here.. DatasetInit.Tables.Add(tblSliceInfo)
6
2422
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The connection string works fine and the tables are added to the project without a problem. When I create the tables they appear to bind and I am able to preview the data in the database in design mode; however, at runtime no data is displayed and the...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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,...
1
10096
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
9956
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
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
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
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.