473,511 Members | 15,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to update datatable

2 New Member
Hi All!
I want to update a record in my database but without using "update mytblname" query.
I am using following code
Expand|Select|Wrap|Line Numbers
  1. sql = "select * from customer where id = " & Val(Me.id.Text)
  2.  
  3.  
  4.         Dim adapter As New SqlDataAdapter(sql, conn)
  5.         Dim builder As SqlCommandBuilder = New SqlCommandBuilder(adapter)
  6.         Dim ds1 As New DataSet("customer")
  7.         adapter.Fill(ds1, "customer")
  8.         Dim T As DataTable = ds1.Tables("customer")
  9.         Dim i As Integer
  10.         Dim row As DataRow
  11.         If T.Rows.Count = 0 Then
  12.             row = T.NewRow
  13.         Else
  14.             T.Rows(0).BeginEdit()
  15.             row = T.Rows(0)
  16.             row.BeginEdit()
  17.         End If
  18.  
  19.         row("cname") = cname.Text
  20.         If addre.Text = "" Then addre.Text = "-"
  21.         row("address") = Me.addre.Text
  22.         If email.Text = "" Then email.Text = "-"
  23.         row("email") = email.Text
  24.         If ph.Text <> "" Then row("ph") = ph.Text
  25.         If cont.Text <> "" Then row("cont") = cont.Text
  26.         If other.Text <> "" Then row("other") = other.Text
  27.         If desi.Text <> "" Then row("desi") = desi.Text
  28.         row("zone") = Me.cmbzone.Text
  29.         If Val(Me.id.Text) = 0 Then
  30.             T.Rows.Add(row)
  31.             '  Else
  32.         Else
  33.             T.Rows(0).EndEdit()
  34.             row.EndEdit()
  35.         End If
  36.         adapter.Update(ds1, "customer")
  37.         adapter.Dispose()Its giving me error.
  38.  
WHat is problem with above code ?
Data is not getting updated to database/
Jun 12 '09 #1
3 2370
madankarmukta
308 Contributor
@ashukla
Hi ,

As per my understanding you r going in the worng direction..

You wann to update the database Customer table from the table which is there in the ds1 dataset... Wright ?

If this is the case ..you need to use the ExecuteNonQuery() function of the DataAdapter..

Just have a look of Dataadapter.ExecuteNonQuery() and get your task done..

Please let me know about any clarification..

Thanks!
Jun 12 '09 #2
ashukla
2 New Member
Thanks for reply.
But i dont want to use "Update table .." query.
Hence i am using above code.
Jun 12 '09 #3
madankarmukta
308 Contributor
@ashukla
I think you have performance issue with using "Update table.." query..

Okay fine.. Just perform the ds1.AcceptChanges() before calling the adapter.Update() function.

Please let me know for the qury if any.

Thanks!
Jun 12 '09 #4

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

Similar topics

2
12056
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really...
8
14811
by: ZeroVisio | last post by:
Hi, I want to know if there is an easy way to do update a column of a row in DataTable.
1
2961
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
9
12953
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
8
2673
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
2513
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
4
11151
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
1
12107
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row...
4
4825
by: Matteo Migliore | last post by:
Hi. I writed a method that takes two DataTable with same schema and return a third DataTable that: - insert new rows from "compare" DataTable - delete rows contained in "source" and not in...
0
3097
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
0
7245
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,...
0
7144
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
7356
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,...
1
7085
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
7512
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...
0
5671
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,...
1
5069
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...
0
1577
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 ...
1
785
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.