|
|
#1 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Retrieving and Saving Data in Databases
C# version here.
There is all sorts of literature on this topic but people still keep asking the same questions. I'm creating this thread so I can send people here to look at some example code that I know will demonstrate all the principles they need. These principles can be extended or adjusted and applied to any data access situation. This code uses members of the System.Data.SqlClient namespace. If you're not using SQL Server then it's a simple matter of switching to the corresponding types of the appropriate namespace for your data source. For example, if you're using an Access database then you'd use an OleDb.OleDbConnection rather than an SqlClient.SqlConnection. Retrieving a single value. The ExecuteScalar method returns the value from the first column of the first row of the query's result set: vb.net Code:
vb.net Code:
vb.net Code:
Retrieving multiple records for display and editing, then saving the changes. The DataAdapter.Fill method populates a DataTable with the contents of the result set of a query. The DataAdapter.Update method saves the changes in a DataTable in accordance with the SQL statements contained in the DeleteCommand, InsertCommand and UpdateCommand properties: vb.net Code:
vb.net Code:
vb.net Code:
Note also the DataAdapter.Fill, DataAdapter.Update and Command.ExecuteNonQuery methods are all functions. All three return an Integer that contains the number of records that were either retrieved (Fill) or saved (Update, ExecuteNonQuery). Finally, this code uses all the "old style" data access types. In .NET 2.0 I suggest creating a Data Source to generate a typed DataSet and TableAdapters. The principles there are basically the same except that you have to write less code. All SQL statements are added via the DataSet designer and all you really have to do is create TableAdapters and call their methods. Even the connections are hidden within the TableAdapters so it's all much easier. Understanding what's above should help you understand how TableAdapters work internally though. EDIT: Note that I have updated the code examples slightly in this post and post #3 to more accurately reflect real usage situations, particularly using a DataAdapter to get and save data in separate methods rather than in the same method.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET Last edited by jmcilhinney; Nov 8th, 2008 at 07:30 PM. |
|
|
|
|
|
#2 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
To find the appropriate connection string for your ADO.NET provider visit www.connectionstrings.com.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#3 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Inserting multiple records into a table. This situation is much like the fourth example above, except you don't need to retrieve any data to start with and you obviously don't need the UpdateCommand and DeleteCommand:
vb.net Code:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET Last edited by jmcilhinney; Apr 22nd, 2009 at 02:57 AM. |
|
|
|
|
|
#4 |
|
New Member
Join Date: Jan 08
Posts: 2
![]() |
Re: Retrieving and Saving Data in Databases
hi jmcilhinney,
Its a nice documentation. (This is my first post.) Still i would request a good class/module for db connection in access. Particularly i need to access ms access though local network.what would be the best class code. I appreciate your view. I think you will help me and people like me. I m trying to work in .net.i have done little programmings in vb6 and .net 05. i have been on this site for last 4-6 hrs. got excellent helping examples and links. Thanks again. |
|
|
|
|
|
#5 | ||
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
||
|
|
|
|
|
#6 |
|
Lively Member
Join Date: Jun 08
Location: Philippines
Posts: 69
![]() |
Re: Retrieving and Saving Data in Databases
Hi, I found your compilation verry usefull in my project... Thank you... Since I'm a new user of VB Express Edition 2008, can you help me in my problem regarding retrieving a recordset and afterwards editing one of its field.
Additional Info: in the first scenario, im going to create a new data, and because this is a Time keeping System, First Im just going to get the Time IN and leave the TimeOUT Column blank.. what i want to do is i want to retrive this recordset and update the TimeOUT column. Thanks. Table: TIME_IN_OUT EmpNo TimeIN TimeOUT 00001 8:30 AM N/A |
|
|
|
|
|
#7 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#8 |
|
New Member
Join Date: Oct 08
Posts: 13
![]() |
Okay I am using the code below:
Code:
Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\Richard Colbert\Documents\Visual Studio 2008\Projects\WindowsApplication1\WindowsApplication1\shenandoah.accdb'")
Dim adapter As New OleDb.OleDbDataAdapter("SELECT ID, Date, Driver, Truck, Customer, Rate, Where_From, Where_To, Pit_Ticket, PO_Number, Yards_Tons, Description, QP_Fee, Fuel, Expenses, Advances FROM Shenandoahs", connection)
Dim insert As New OleDb.OleDbCommand("INSERT INTO Shenandoahs (Date, Driver, Truck, Customer, Rate, Where_From, Where_To, Pit_Ticket, PO_Number, Yards_Tons, Description, QP_Fee, Fuel, Expenses, Advances) VALUES (@Date, @Driver, @Truck, @Customer, @Rate, @Where_From, @Where_To, @Pit_Ticket, @PO_Number, @Yards_Tons, @Description, @QP_Fee, @Fuel, @Expenses, @Advances)", connection)
insert.Parameters.Add("@Date", OleDb.OleDbType.VarChar, 20, "mmddyy")
insert.Parameters.Add("@Driver", OleDb.OleDbType.VarChar, 20, "Driver")
insert.Parameters.Add("@Truck", OleDb.OleDbType.VarChar, 10, "Truck")
insert.Parameters.Add("@Customer", OleDb.OleDbType.VarChar, 10, "Customer")
insert.Parameters.Add("@Rate", OleDb.OleDbType.VarChar, 10, "Rate")
insert.Parameters.Add("@Where_From", OleDb.OleDbType.VarChar, 100, "Where_From")
insert.Parameters.Add("@Where_To", OleDb.OleDbType.VarChar, 100, "Where_To")
insert.Parameters.Add("@Pit_Ticket", OleDb.OleDbType.VarChar, 20, "Pit_Ticket")
insert.Parameters.Add("@PO_Number", OleDb.OleDbType.VarChar, 20, "PO_Number")
insert.Parameters.Add("@Yards_Tons", OleDb.OleDbType.VarChar, 20, "Yards_Tons")
insert.Parameters.Add("@Description", OleDb.OleDbType.VarChar, 100, "Description")
insert.Parameters.Add("@QP_Fee", OleDb.OleDbType.VarChar, 20, "QP_Fee")
insert.Parameters.Add("@Fuel", OleDb.OleDbType.VarChar, 20, "Fuel")
insert.Parameters.Add("@Expenses", OleDb.OleDbType.VarChar, 20, "Expenses")
insert.Parameters.Add("@Advances", OleDb.OleDbType.VarChar, 20, "Advances")
adapter.InsertCommand = insert
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim table As New DataTable
'Retrieve the data.
adapter.FillSchema(table, SchemaType.Source)
'Add the new rows to the DataTable, e.g.
Dim row As DataRow = table.NewRow()
row("Date") = mmddyy
row("Driver") = Driver
row("Truck") = Truck
row("Customer") = Customer
row("Rate") = Rate
row("Where_From") = Where_From
row("Where_To") = Where_To
row("Pit_Ticket") = Pit_Ticket
row("PO_Number") = Po_Number
row("Yards_Tons") = Yards_Tons
row("Description") = Description
row("QP_Fee") = QP_Fee
row("Fuel") = Fuel
row("Expenses") = Expenses
row("Advances") = Advances
table.Rows.Add(row)
'Save the changes.
adapter.Update(table)
Syntax error in INSERT INTO statement. I have been trying to get this to work for like HOURS. Please help! |
|
|
|
|
|
#9 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#10 |
|
New Member
Join Date: Oct 08
Posts: 13
![]() |
Re: Retrieving and Saving Data in Databases
Okay you where so write about the date....I renamed all my fields in the database and in my code to mmddyy and it started working, well sort of....it is writing to the database now but it is not filling the database with the information from the form, instead all my fields say either: "System.Windows.Forms", "System.Win", or "System.Windows.Forms.TextBox,Text:"
WTH - Here is the complete revised code: Code:
Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\Richard Colbert\Documents\Visual Studio 2008\Projects\WindowsApplication1\WindowsApplication1\shenandoah.accdb'")
Dim adapter As New OleDb.OleDbDataAdapter("SELECT ID, mmddyy, Driver, Truck, Customer, Rate, Where_From, Where_To, Pit_Ticket, PO_Number, Yards_Tons, Description, QP_Fee, Fuel, Expenses, Advances FROM Shenandoahs", connection)
Dim insert As New OleDb.OleDbCommand("INSERT INTO Shenandoahs (mmddyy, Driver, Truck, Customer, Rate, Where_From, Where_To, Pit_Ticket, PO_Number, Yards_Tons, Description, QP_Fee, Fuel, Expenses, Advances) VALUES (@mmddyy, @Driver, @Truck, @Customer, @Rate, @Where_From, @Where_To, @Pit_Ticket, @PO_Number, @Yards_Tons, @Description, @QP_Fee, @Fuel, @Expenses, @Advances)", connection)
insert.Parameters.Add("@mmddyy", OleDb.OleDbType.VarChar, 20, "mmddyy")
insert.Parameters.Add("@Driver", OleDb.OleDbType.VarChar, 20, "Driver")
insert.Parameters.Add("@Truck", OleDb.OleDbType.VarChar, 10, "Truck")
insert.Parameters.Add("@Customer", OleDb.OleDbType.VarChar, 10, "Customer")
insert.Parameters.Add("@Rate", OleDb.OleDbType.VarChar, 10, "Rate")
insert.Parameters.Add("@Where_From", OleDb.OleDbType.VarChar, 100, "Where_From")
insert.Parameters.Add("@Where_To", OleDb.OleDbType.VarChar, 100, "Where_To")
insert.Parameters.Add("@Pit_Ticket", OleDb.OleDbType.VarChar, 20, "Pit_Ticket")
insert.Parameters.Add("@PO_Number", OleDb.OleDbType.VarChar, 20, "PO_Number")
insert.Parameters.Add("@Yards_Tons", OleDb.OleDbType.VarChar, 20, "Yards_Tons")
insert.Parameters.Add("@Description", OleDb.OleDbType.VarChar, 100, "Description")
insert.Parameters.Add("@QP_Fee", OleDb.OleDbType.VarChar, 20, "QP_Fee")
insert.Parameters.Add("@Fuel", OleDb.OleDbType.VarChar, 20, "Fuel")
insert.Parameters.Add("@Expenses", OleDb.OleDbType.VarChar, 20, "Expenses")
insert.Parameters.Add("@Advances", OleDb.OleDbType.VarChar, 20, "Advances")
adapter.InsertCommand = insert
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim table As New DataTable
'Retrieve the data.
adapter.FillSchema(table, SchemaType.Source)
'Add the new rows to the DataTable, e.g.
Dim row As DataRow = table.NewRow()
row("mmddyy") = mmddyy
row("Driver") = Driver
row("Truck") = Truck
row("Customer") = Customer
row("Rate") = Rate
row("Where_From") = Where_From
row("Where_To") = Where_To
row("Pit_Ticket") = Pit_Ticket
row("PO_Number") = Po_Number
row("Yards_Tons") = Yards_Tons
row("Description") = Description
row("QP_Fee") = QP_Fee
row("Fuel") = Fuel
row("Expenses") = Expenses
row("Advances") = Advances
table.Rows.Add(row)
'Save the changes.
adapter.Update(table)
End Sub
|
|
|
|
|
|
#11 |
|
Addicted Member
Join Date: Sep 08
Location: Jacksonville, Florida
Posts: 147
![]() |
Re: Retrieving and Saving Data in Databases
row("mmddyy") = mmddyy
row("Driver") = Driver So mmddyy in this instance would be a text box? you need to do this instead if that's the case: row("mmddyy")=mmddyy.text |
|
|
|
|
|
#12 |
|
New Member
Join Date: Oct 08
Posts: 13
![]() |
Re: Retrieving and Saving Data in Databases
Thanks so much MaslowB and jmcilhinney that code is working now.
Now I have another question....I need it to select which table to write to based on the user selection in the "Company" field on my form. There are three divisions to this company and thus three different databases. Those divisions are: "Shenandoah", "Shenandoahs_Covered_Wagon" and "Shenandoahs_Heavy_Haul" each with tables in the db named the same. All fields submitted to the tables are the same, it just needs to know which table to submit (input) to. |
|
|
|
|
|
#13 |
|
Addicted Member
Join Date: Sep 08
Location: Jacksonville, Florida
Posts: 147
![]() |
Re: Retrieving and Saving Data in Databases
Dim insert As New OleDb.OleDbCommand("INSERT INTO "+company.text+"(mmddyy, Driver, Truck, Customer, Rate, Where_From, Where_To, Pit_Ticket, PO_Number, Yards_Tons, Description, QP_Fee, Fuel, Expenses, Advances) VALUES (@mmddyy, @Driver, @Truck, @Customer, @Rate, @Where_From, @Where_To, @Pit_Ticket, @PO_Number, @Yards_Tons, @Description, @QP_Fee, @Fuel, @Expenses, @Advances)", connection)
How about that? |
|
|
|
|
|
#14 |
|
New Member
Join Date: Oct 08
Posts: 13
![]() |
Re: Retrieving and Saving Data in Databases
That would probably work a lot easier and shorten my code a tad, but I figured it out using this:
If Company.Text = "Shenandoah" Then original code here ElseIf Company.Text = "Shenandoahs_Covered_Wagon" Then revised code here ElseIf Company.Text = "Shenandoahs_Heavy_Haul" Then more revised code here End If Not nearly as pretty or as short but it worked flawlessly. I will remember your suggestion and when I go through and revise (shorten my code) I will implement it. |
|
|
|
|
|
#15 |
|
Addicted Member
Join Date: Sep 08
Location: Jacksonville, Florida
Posts: 147
![]() |
Re: Retrieving and Saving Data in Databases
mark your thread resolved, rate those users that helped =)
|
|
|
|
|
|
#16 |
|
New Member
Join Date: Oct 08
Posts: 13
![]() |
Okay I rated both of you who helped me going to mark my original thread on this issue resolved....I have posted a new thread with a new issue if you guys can help again it would be greatly appreciated. Thanks!
|
|
|
|
|
|
#17 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Note that I have updated the code examples slightly in posts #1 and #3 to more accurately reflect real usage situations, particularly using a DataAdapter to get and save data in separate methods rather than in the same method.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#18 |
|
Junior Member
Join Date: Sep 08
Posts: 21
![]() |
Re: Retrieving and Saving Data in Databases
vb Code:
Why in this code snippet you don't close the connection?and how do you handle a exception(database exception)? thanks |
|
|
|
|
|
#19 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
As I said in my first post, I haven't included any exception handling because that's a separate topic that isn't related to data access specifically. In a real situation, yes, you would provide appropriate exception handling. For this example I didn't want to draw attention away from the actual topic of the thread, which is the data access itself. In a real situation you might put the exception handler inside the Using block(s) or outside, depending on the circumstances and your preference. One of the reasons you should use Using blocks is that they ensure that an object is disposed even if an exception is thrown, so you don't have to do anything extra to dispose the data access objects. vb.net Code:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#20 |
|
Hyperactive Member
Join Date: Apr 07
Posts: 354
![]() |
Re: Retrieving and Saving Data in Databases
@JM
Hi i tried your codes to retrieve and update data in my textbox which is bound to a field in database. When i launch the application the textbox does not display the data?? can you tell me what could be possibly wrong?? vb Code:
|
|
|
|
|
|
#21 |
|
Hyperactive Member
Join Date: Apr 07
Posts: 354
![]() |
Re: Retrieving and Saving Data in Databases
anyone plz help!! y is this not working?
|
|
|
|
|
|
#22 | |
|
Hyperactive Member
Join Date: Apr 07
Posts: 354
![]() |
Re: Retrieving and Saving Data in Databases
I tried this piece of code to update the datarow where value of the MachineID is textbox1.text
vb Code:
And i am getting this error: Quote:
|
|
|
|
|
|
|
#23 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
@LuxCoder
With regards to post #20, are you actually calling those methods at all, i.e. are you actually getting any data? Even if you are, are you binding your DataTable to your TextBox? If you don't retrieve data and put it into the TextBox then the TextBox won't show any data. With regards to post #21, please do not EVER bump a thread like that but especially not someone else's CodeBank thread. Please don't clutter up the useful information with pointless bumps that are against forum rules. With regards to post #22, you've got a syntax error in your SQL because you've got an INSERT statement with a WHERE clause. Have you read the information provided in this thread? Look at the syntax used for INSERT and UPDATE statements. INSERT is used to add a new record while UPDATE is used to edit an existing record. Work out which one it is that you want to do and use the appropriate SQL syntax.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#24 |
|
Addicted Member
Join Date: Feb 08
Location: Japan
Posts: 214
![]() |
Re: Retrieving and Saving Data in Databases
Question, in this line of code:
Code:
dbAdpPatronType.Fill(dbDsetPatron, "PatronType") [adaptername].fill([datasetname],[datatablename?])
__________________
ほんとにどもありがとう! |
|
|
|
|
|
#25 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
vb.net Code:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#26 |
|
Addicted Member
Join Date: Feb 08
Location: Japan
Posts: 214
![]() |
Re: Retrieving and Saving Data in Databases
So then:
Code:
Dim dbConn As New SqlConnection
Dim dbAdp As SqlDataAdapter
Dim dbDset As DataSet
dbConn.ConnectionString = "Integrated Security=SSPI; Initial Catalog=DB; Persist Security Info=False;"
dbConn.Open()
dbAdp = New SqlClient.SqlDataAdapter("SELECT * FROM table", dbConn)
dbDset = New DataSet
dbAdp.Fill(dbDset, "Table")
__________________
ほんとにどもありがとう! |
|
|
|
|
|
#27 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
|
#28 |
|
Addicted Member
Join Date: Feb 08
Location: Japan
Posts: 214
![]() |
Re: Retrieving and Saving Data in Databases
So then, how can I clear the contents of a single datatable in a dataset? I believe the dataset.clear() method clears the whole dataset, is there something like a datatable.clear()? And what would be the syntax for clearing a specific datatable, if there is such a method in .net?
__________________
ほんとにどもありがとう! |
|
|
|
|
|
#29 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,910
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Retrieving and Saving Data in Databases
Quote:
As for the question, have you read the documentation? That should ALWAYS be your first source of information. If you want to do something with a DataTable then read the documentation for the DataTable class. That will tell you definitively whether there's a DataTable.Clear method.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|