Hello
I'm a newbie who has a problem with updating the dataset into the
database. Maybe I missed a few lines of codes. Please shed some light
for me. The following code is working but not like I wanted.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dsn As String = ConfigurationSettings.AppSettings("dsn")
oConn = New OleDbConnection(dsn)
Dim intKey As Integer = CInt(Request.QueryString("id"))
BindData(intKey)
End Sub
Private Sub BindData(ByVal int As Integer)
strQ = "SELECT Name, Company, WorkAddress, DirectLine, ID
FROM Ad WHERE ID = " & intKey
oDaAd = New OleDbDataAdapter(strQ, oConn)
oCbAd = New OleDbCommandBuilder(oDaAd)
oDaAd.InsertCommand = oCbAd.GetInsertCommand
oDaAd.UpdateCommand = oCbAd.GetUpdateCommand
Try
oConn.Open()
oDsAd.Clear()
oDaAd.MissingSchemaAction = MissingSchemaAction.AddWithKey
oDaAd.Fill(oDsAd, "Ad")
txtCoName.DataBind()
txtPIC.DataBind()
txtDirectLine.DataBind()
Catch ex As Exception
Label1.Text = ex.ToString()
Finally
If oConn.State = ConnectionState.Open Then
oConn.Close()
End If
End Try
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim dr As DataRow = oDsAd.Tables(0).Rows.Find(intKey)
dr("Name") = txtPIC.Text
dr("Company") = txtCoName.Text
dr("DirectLine") = txtDirectLine.Text
Try
oConn.Open()
oDaAd.Update(oDsAd, "Ad")
Catch ex As Exception
Label1.Text = ex.ToString()
Finally
oConn.Close()
End Try
With DataGrid1
.DataSource = oDsAd
.DataBind()
End With
In the aspx page
<asp:textbox id=txtPIC style="Z-INDEX: 126; LEFT: 200px; POSITION:
absolute; TOP: 88px" tabIndex=3 runat="server" Text='<%#
DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].Name") %>'
Width="358px"></asp:textbox>
<asp:textbox id=txtCoName style="Z-INDEX: 124; LEFT: 200px; POSITION:
absolute; TOP: 56px" tabIndex=1 runat="server" Text='<%#
DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].Company") %>'
Width="358px"></asp:textbox>
<asp:textbox id=txtDirectLine style="Z-INDEX: 133; LEFT: 200px;
POSITION: absolute; TOP: 424px" tabIndex=11 runat="server" Text='<%#
DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].DirectLine") %>'
After executing the codes, the dataset doesnt have the changes that I
have made in the textboxes i.e they contains the original values. But
when I made the following changes, the columns of the table is updated
with the values they are assigned to.
dr("Name") = "me"
dr("Company") = "myCo"
dr("DirectLine") = 1234
Where did I done wrong? Is it because of the binding? I need to bind it
because I'm populationg the controls with the existing data from the
database.
I thank you in advance for your help. 3 1339
the core problem is that bind doesn't quite work the way that one would
think -- you are doing too much work, however... the framework will do
most of the heavy lifting for you.
take a look at this for a working example (it's a datalist binding
example) http://code.box.sk/forum.php?did=mul...T&thread=13833
Hi,
"virlinz" <vi*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... Hello I'm a newbie who has a problem with updating the dataset into the database. Maybe I missed a few lines of codes. Please shed some light for me. The following code is working but not like I wanted.
I'm not very familar with asp.net and databinding, but don't you need to
check if it is a postback and if it is, then don't reload the data,
otherwise you're restoring the values:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dsn As String = ConfigurationSettings.AppSettings("dsn")
oConn = New OleDbConnection(dsn)
If ( Not IsPostBack ) Then
Dim intKey As Integer = CInt(Request.QueryString("id"))
BindData(intKey)
End if
End Sub
HTH,
Greetings Private Sub BindData(ByVal int As Integer) strQ = "SELECT Name, Company, WorkAddress, DirectLine, ID FROM Ad WHERE ID = " & intKey
oDaAd = New OleDbDataAdapter(strQ, oConn) oCbAd = New OleDbCommandBuilder(oDaAd)
oDaAd.InsertCommand = oCbAd.GetInsertCommand oDaAd.UpdateCommand = oCbAd.GetUpdateCommand
Try oConn.Open() oDsAd.Clear() oDaAd.MissingSchemaAction = MissingSchemaAction.AddWithKey oDaAd.Fill(oDsAd, "Ad") txtCoName.DataBind() txtPIC.DataBind() txtDirectLine.DataBind()
Catch ex As Exception Label1.Text = ex.ToString()
Finally If oConn.State = ConnectionState.Open Then oConn.Close() End If End Try End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim dr As DataRow = oDsAd.Tables(0).Rows.Find(intKey) dr("Name") = txtPIC.Text dr("Company") = txtCoName.Text dr("DirectLine") = txtDirectLine.Text
Try oConn.Open() oDaAd.Update(oDsAd, "Ad")
Catch ex As Exception Label1.Text = ex.ToString()
Finally oConn.Close()
End Try
With DataGrid1 .DataSource = oDsAd .DataBind() End With
In the aspx page <asp:textbox id=txtPIC style="Z-INDEX: 126; LEFT: 200px; POSITION: absolute; TOP: 88px" tabIndex=3 runat="server" Text='<%# DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].Name") %>' Width="358px"></asp:textbox> <asp:textbox id=txtCoName style="Z-INDEX: 124; LEFT: 200px; POSITION: absolute; TOP: 56px" tabIndex=1 runat="server" Text='<%# DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].Company") %>' Width="358px"></asp:textbox> <asp:textbox id=txtDirectLine style="Z-INDEX: 133; LEFT: 200px; POSITION: absolute; TOP: 424px" tabIndex=11 runat="server" Text='<%# DataBinder.Eval(oDsAd, "Tables[Ad].DefaultView.[0].DirectLine") %>'
After executing the codes, the dataset doesnt have the changes that I have made in the textboxes i.e they contains the original values. But when I made the following changes, the columns of the table is updated with the values they are assigned to. dr("Name") = "me" dr("Company") = "myCo" dr("DirectLine") = 1234
Where did I done wrong? Is it because of the binding? I need to bind it because I'm populationg the controls with the existing data from the database.
I thank you in advance for your help.
Hi stand__sure & Bart Mermuys..
Thanks for the reply. I never use datalist before. I'll try to
understand the codes. I've added the postback codes. thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Richard |
last post by:
Hi,
I'm having issues with DataBinding. I have a Form with two data bound comboboxes on it. When you select something in one combobox I may {or may not} want to change the selected item in the...
|
by: Arne |
last post by:
I am able to use databinding for a selecting a record and
binding it a webform.
I have no idea how to databind a webform for updates. DO
you?
|
by: Nikerz Inc |
last post by:
Hi there,
I want to bind a text box to a column in my dataset and update changes vice
versa. I'm having a rough time to do so any help or examples appreciated!!
Dim sql As String = "SELECT *...
|
by: louise raisbeck |
last post by:
Hi,
There seem to be several ways to update rows in sql. What is the best
practice? I have written a medium sized update statement into a stored
procedure, taking values from the web text...
|
by: John Bailey |
last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great.
The formview and detailview contorls would automatically layout the controls
for you, the update methods were...
|
by: Mark R. Dawson |
last post by:
Hi all,
I may be missing something with how databinding works but I have bound a
datasource to a control and everything is great, the control updates to
reflect the state of my datasource when I...
|
by: Richard Carpenter |
last post by:
I am working on a small project in which I am trying to implement a
data access layer through the use of a project dataset schema. Data
integrity and normalization will be handled through the use...
|
by: Tor Inge Rislaa |
last post by:
Databinding programmatically
In my webform I have the code below in the form_load procedure.
On the webform I have a GridView control. My question is simply how to bind
the GridView to the...
|
by: Vlado Jasovic |
last post by:
Hello,
I'm using typed dataset for databinding to windows controls and I'm having
some problems.
I'm trying to move all business logic to datatable column_changing events
and the problem that...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |