473,804 Members | 3,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save to Database using dataset

mafaisal
142 New Member
Hello
I am Using vb.net 2005 And sql2005
Please see then code below
Expand|Select|Wrap|Line Numbers
  1. Public Sub Saving(ByVal Table As String, ByVal Fields As String, ByVal Values As String)
  2.         Dim DsS As New DataSet
  3.         Dim cmd1 As New OleDbCommand(" Select * From " & Table & " Where 1 =2 ", Con)
  4.         'Dim cmd1 As New OleDbCommand(" Insert into Users Select * From Users Where 1=2 ", Con)
  5.         Dap = New OleDbDataAdapter(cmd1)
  6.         Dap.Fill(DsS, Table)
  7.         Dim DrS As DataRow = DsS.Tables(Table).NewRow
  8.         Dim F = Split(Fields, ",")
  9.         Dim V = Split(Values, ",")
  10.         For i As Integer = 0 To UBound(F)
  11.             DrS.Item(F(i)) = V(i)
  12.         Next
  13.  
  14.         DsS.Tables(Table).Rows.Add(DrS)
  15.         DrS.AcceptChanges()
  16.         Dap.Update(DsS, Table)
  17.         DsS.AcceptChanges()
  18.         MsgBox("ADDED")
  19.  
  20.     End Sub
  21.  
  22.  
In the above code there is no error but there is no affect in database
Please give me Reply
May 29 '08 #1
1 1377
shweta123
692 Recognized Expert Contributor
Hi,

To update the database itself you need to add this line after creating dataAdpter :

e.g.

Expand|Select|Wrap|Line Numbers
  1.  Dap = New OleDbDataAdapter(cmd1)
  2.    Dim cb As New OleDb.OleDbCommandBuilder(Dap)

Hello
I am Using vb.net 2005 And sql2005
Please see then code below
Expand|Select|Wrap|Line Numbers
  1. Public Sub Saving(ByVal Table As String, ByVal Fields As String, ByVal Values As String)
  2.         Dim DsS As New DataSet
  3.         Dim cmd1 As New OleDbCommand(" Select * From " & Table & " Where 1 =2 ", Con)
  4.         'Dim cmd1 As New OleDbCommand(" Insert into Users Select * From Users Where 1=2 ", Con)
  5.         Dap = New OleDbDataAdapter(cmd1)
  6.         Dap.Fill(DsS, Table)
  7.         Dim DrS As DataRow = DsS.Tables(Table).NewRow
  8.         Dim F = Split(Fields, ",")
  9.         Dim V = Split(Values, ",")
  10.         For i As Integer = 0 To UBound(F)
  11.             DrS.Item(F(i)) = V(i)
  12.         Next
  13.  
  14.         DsS.Tables(Table).Rows.Add(DrS)
  15.         DrS.AcceptChanges()
  16.         Dap.Update(DsS, Table)
  17.         DsS.AcceptChanges()
  18.         MsgBox("ADDED")
  19.  
  20.     End Sub
  21.  
  22.  
In the above code there is no error but there is no affect in database
Please give me Reply
May 30 '08 #2

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

Similar topics

4
560
by: HomeyDaClown | last post by:
I'm new to the VB.net world and have been reading alot of books and threw newsgroups Is it even posable to save user input from a form to a data grid. I could just edit the data gri but would prefer useing the user form to import the data Any help would be greatly appreciated Thanks Homey
2
1639
by: Torben Madsen | last post by:
Hello, I'm trying to save the changes back to the database, but it doesn't work -could anybody help me? I'm using a DataSet and the wierd thing is that I can save the changes in the memory but not in the database :-/ I have tried to duplicate an example I found on msdn -but with no luck. The sourcecode is in C#: --------------------------------------------------------------------- Sourcecode
4
6234
by: Jaime | last post by:
I have to save a dataset to xml and for efficiency I like to get rid of the namespace prefix d2p1: can any one help thanks jaime
2
4828
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different row selected in the datagrid. I want to save the changes that user make in the textboxes when they select a different row in the datagrid. I tried capturing the textbox.text at datagrid's CurrentCellChanged event but by then the textbox.text...
4
4538
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a tab delimited file or an excel file. The application then saves the file in the correct format. The flip side is for the user to import/upload the file to the server The application must be able to import the excel file and read the contents. I...
1
2877
by: Asha | last post by:
greetings, i've manually created a dataset which contains data input from users. i validate the dataset against the business logic and once everything is done, i would like to save the values in the dataset into the database. the database has 5 columns and so does my dataset. my dataset has all the same name field name and datatype as the database. is there a possibility to merge the dataset in to the database? i was hoping there...
2
1899
by: buran | last post by:
Dear ASP.NET Programmers, I am saving the tables of a dataset into an XML file. I want to save the XML file into the database, then retireve it as a dataset. I use the following code: ds.WriteXml("C:\Inetpub\wwwroot\database2\richtext\burak.xml") where ds is my dataset.
2
2004
by: Lawrence Chang | last post by:
Hi My friends, Can I save dataset object to an application variable? I want all the customer use this dataset. and diffrent customer create diffrent dataview object from this dataset, so it don't need to connect to database everytime .. I know I can use cache object , but cache object can be deleted automatically if server's memory is low, is this correct? Would you like to give me more information about how to improve database webform...
6
5829
by: Dhananjay | last post by:
hi everyone i have a problem how to save the textbox contents to sql server database. i am getting this contents after conversion from web browser into textbox(multiline) I want to store all the contents of textbox in sql server database. i ahve generated a table. if u have any idea then let me know the coding for this in C#.net
0
1901
by: Rob | last post by:
I have a Webservice written in C# that provides data to both a web browser through ASP.net and to a VC++ client. I have been able to retrieve data from SQLServer and passing to my C++ client as XML without a problem using the SqlDataAdaptor and the DataSet. I am a bit confused how to save data to SQL Server from my client. I figured if I could create a DataSet, I could save it to the database. I wrote a WebMethod that takes a string...
0
9705
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
10567
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
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
6847
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
5515
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
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.