473,383 Members | 1,997 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,383 software developers and data experts.

Save to Database using dataset

mafaisal
142 100+
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 1361
shweta123
692 Expert 512MB
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
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...
2
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...
4
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
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...
4
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...
1
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...
2
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: ...
2
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...
6
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
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
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...

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.