473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Dim dv As DataView = Me.TerrDataSet.Tables(0).DefaultView
Me.DataBind()
Me.SqlConnection1.Close()
Me.Session.Add("DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Session.Item("DataSet"), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.Close()
End Sub

Lloyd Sheen
Nov 18 '05 #1
3 1560
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(maintain 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.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Dim dv As DataView = Me.TerrDataSet.Tables(0).DefaultView
Me.DataBind()
Me.SqlConnection1.Close()
Me.Session.Add("DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Session.Item("DataSet"), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.Close()
End Sub

Lloyd Sheen

Nov 18 '05 #2
Ok, things are getting really strange. First I edit the
UpdateCommand.CommandText 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
TerritoryDescription = @TerritoryDescription, RegionID = @RegionID WHERE
(TerritoryID = @TerritoryID)"
SqlDataAdapter1.UpdateCommand.Parameters("@RegionI D").Value =
Me.TextBox1.Text
SqlDataAdapter1.UpdateCommand.Parameters("@Territo ryDescription").Value =
Me.TextBox2.Text
SqlDataAdapter1.UpdateCommand.Parameters("@Territo ryID").Value =
Me.TextBox3.Text
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)

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*******@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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(maintain 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.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Dim dv As DataView = Me.TerrDataSet.Tables(0).DefaultView
Me.DataBind()
Me.SqlConnection1.Close()
Me.Session.Add("DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Session.Item("DataSet"), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.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 TerritoryDescription = @TerritoryDescription,
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 =, TerritoryDescription =
@TerritoryDescription, 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*******************@tostopspamhotmail.com> wrote in message
news:SG*********************@news04.bloor.is.net.c able.rogers.com...
Ok, things are getting really strange. First I edit the
UpdateCommand.CommandText 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
TerritoryDescription = @TerritoryDescription, RegionID = @RegionID WHERE
(TerritoryID = @TerritoryID)"
SqlDataAdapter1.UpdateCommand.Parameters("@RegionI D").Value =
Me.TextBox1.Text
SqlDataAdapter1.UpdateCommand.Parameters("@Territo ryDescription").Value = Me.TextBox2.Text
SqlDataAdapter1.UpdateCommand.Parameters("@Territo ryID").Value =
Me.TextBox3.Text
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)

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*******@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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(maintain 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.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Dim dv As DataView = Me.TerrDataSet.Tables(0).DefaultView
Me.DataBind()
Me.SqlConnection1.Close()
Me.Session.Add("DataSet", Me.TerrDataSet)
Else
Me.TerrDataSet = CType(Me.Session.Item("DataSet"), TerrDataSet)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)
Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.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
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...
6
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. ...
0
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...
2
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...
19
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...
0
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...
14
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...
9
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.