Hi everybody,I’v a question in a Vb.Net 2003 program,How can save or(insert) all the rows that I fill in a datagrid to be saved in itis datasource(table)at one time ,because my insertion code just save and insert the row where the curser is on it.So,IS there a solution.
With thanks, here is my code, - Imports System.Data.OleDb
-
Public Class Form7
-
Inherits System.Windows.Forms.Form
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim strcon As String
-
Try
-
strcon = " provider=microsoft.jet.oledb.4.0;data source=Cars.mdb "
-
-
Dim con As New OleDbConnection(strcon)
-
con.Open()
-
-
Dim adapter As New OleDbDataAdapter("select OrderNo,CarName,Model,Color,Quantity,OrderDate from CompanyOrders", con)
-
-
Dim dset As New DataSet
-
-
adapter.Fill(dset, "CompanyOrders")
-
-
dset.Clear()
-
DataGrid1.DataSource = dset.Tables("CompanyOrders")
-
-
Catch exp As Exception
-
MsgBox(exp.ToString)
-
End Try
-
End Sub
-
-
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
-
Dim strcon As String
-
Try
-
strcon = "provider=microsoft.jet.oledb.4.0;data source=Cars.mdb"
-
Dim con As New OleDbConnection(strcon)
-
con.Open()
-
Dim cmd As New OleDbCommand
-
cmd.CommandText = "insert into CompanyOrders(OrderNo,CarName,Model,Color,Quantity,OrderDate) values(" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0) & ",'" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 1) & "', " & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2) & " , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3) & "' , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 4) & "' , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 5) & "')"
-
cmd.Connection = con
-
-
-
-
cmd.ExecuteNonQuery()
-
MessageBox.Show("The addition process done successfully")
-
-
con.Close()
-
Catch exp As Exception
-
MsgBox(exp.ToString)
-
End Try
-
End Sub
-
-
-
-
-
End Class
2 3184
Please help me,I donot know how to solve this problem.
O.K is there any different way I can use it ,i need a tool as datagrid has many rows to fill it with data as Company Orders(ord_num,ord_name,ord_qty,ord_date).
Banfa 9,065
Expert Mod 8TB
I am no VB expert but from a general programming point of view I would have thought that you need to replace the code line -
cmd.CommandText = "insert into CompanyOrders(OrderNo,CarName,Model,Color,Quantity ,OrderDate) values(" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0) & ",'" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 1) & "', " & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2) & " , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3) & "' , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 4) & "' , '" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 5) & "')"
with a for loop (VB has for loops right?) which performs an insert for each row in the data grid and instead of DataGrid1.CurrentCell.RowNumber you use your loop control variable.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Angie |
last post by:
datagrid ex.
a 1 checkbox
b 2 checkbox
c 3 checkbox
once a user selects these 3 rows from a datagrid and i
want to save the 1, 2, 3 value into the database how do i
do this?
I know...
|
by: chrisben |
last post by:
Hi,
I made a DataTable table and add four DataColumn to it.
Then I created a DataView by calling dbv=new DataView
(table). Then I insert some rows to the dataview and bind
it to my datagrid as...
|
by: Bill Toulias |
last post by:
I want to be able to display the tuples of a select query (which may change
at runtime, so no prior knowledge for column characteristics) and edit them
as well.
I used this code, that executes...
|
by: VM |
last post by:
I'm trying to dynamically display the rows in a datagrid while filling the
datatable source. I'm doing it this way because we had already finished the
app but this section sometimes took so long...
|
by: VM |
last post by:
Initially, I had created my Windows application so that my datagrid's source
would be updated once the method that filled the table was finished:
private void btn_run_Click(object sender,...
|
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...
|
by: tnks |
last post by:
hi
i have a data grid (i fill when i run the program) then the user insert rows
and i wana save..
i used SqlClient.SqlCommandBuilder but it fail, just save 1 recordr, some
times 2 records,...
|
by: alexia.bee |
last post by:
Hi all,
I am new to C# so please bear me :).
I have an app which uses datagridview. it has 8 columns.
I also have struct which has 8 members(the same as the datagridview).
when I add row to...
|
by: nch1978 |
last post by:
I am new to programming and am sorry if this post is in the wrong area. I have a listbox bound to a table and a datagrid bound to another one with a connection through xml. I can change the data...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |