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

How to Insert recprd from datagrid to a table?

Mel
Hi,

I created a form that would search a record from a table
and showed the details in datagrid. I have another button
that would insert the records showed in the datagrid to
another table..How will I do this?

Nov 20 '05 #1
4 1430
Hi Mel

Are you talking about web or winform, the two datagrids are completly
different while using them is even more different.

Cor
Nov 20 '05 #2
Mel
Im talking bout Winform..
Nov 20 '05 #3
Hi Mel,

I made a sample for you.
The begin is only to make the table.
In button1 is done as you said to select
In button2 is made the table, with one difference, I take the ones which are
not selected to make the sample more meaningful.

I hope this helps?

Cor
\\\Needs a datagrid and 2 buttons on a form
'The begin is to make the table
Dim dt As DataTable
Dim dv As DataView
Private Sub Form1_Load(ByVal sender As _
Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt = New DataTable("Names")
dt.Columns.Add("IdName")
dt.Columns.Add("Name")
dt.Columns.Add("Country")
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
dt.Rows(0)(1) = "Herfried K. Wagner"
dt.Rows(1)(1) = "Armin Zingler"
dt.Rows(2)(1) = "Ken Tucker"
dt.Rows(3)(1) = "CJ Taylor"
dt.Rows(4)(1) = "Jay B. Harlow"
dt.Rows(5)(1) = "Cor Ligthert"
dt.Rows(0)(2) = "EU"
dt.Rows(1)(2) = "EU"
dt.Rows(2)(2) = "US"
dt.Rows(3)(2) = "US"
dt.Rows(4)(2) = "US"
dt.Rows(5)(2) = "EU"
DataGrid1.DataSource = dt
End Sub
'
'Here start the sample
Private Sub Button1_Click(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
dv = New DataView(dt)
dv.Sort = "Name"
dv.RowFilter = "Country = 'EU'"
DataGrid1.DataSource = dv
End Sub
Private Sub Button2_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt2 As New DataTable("newnames")
dv.RowFilter = "Country = 'US'"
dt2 = dt.Clone
For Each drv As DataRowView In dv
dt2.ImportRow(drv.Row)
Next
DataGrid1.DataSource = dt2
///
Nov 20 '05 #4
Mel
Thanks Cor I'll try your code..your code seems simplified. Thanks a lot
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: adove | last post by:
I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it...
0
by: Christopher | last post by:
I AM GETTING A SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION ERROR WHEN ATTEMPTING TO INSERT DATA INTO A SINGLE TABLE THROUGH A GRID //If this is due to a spelling error, i will //inflict a ritual...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
0
by: Eustice Scrubb | last post by:
In line coding problem. Here's my code: <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL...
10
by: jaYPee | last post by:
as of now i am using a stored procedure from my sql server 2000 to insert record from another table. what i need now is on how can i insert record by not using the stored procedure and insert it...
0
by: Irfan | last post by:
hi, I am trying to insert data into an MSAccess table through a datagrid. I did it by creating a custom Insert Command. However, the table has a foreignKey,which obviously is hidden to the user...
4
by: RG | last post by:
Using VB.NET, How do I insert rows from a SQL Server table into an Access table with the same structure (and also the reverse, from Access to SQL)? I’m new to this, so here’s what I’ve...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
3
by: RN1 | last post by:
This is how I am trying to insert a new record in a database table & then display all the records (including the newly inserted record) in a DataGrid: <script runat="server"> Sub...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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
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,...

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.