tashiduks
Member
- Joined
- Apr 19, 2010
- Messages
- 22
- Programming Experience
- Beginner
Hi Everyone,
Currently i am working with Datagrid. I want to move the data from one datagrid to another. I can populate the data in datagrid using combo box. Now i am stuck with how to move the data between datagrid and save the data using save button.
I following code till now which is working correctly:
Till now its fine. Now what i want in my project is, "i want to move the data from one datagrid to another datagrid after loading the data to datagrid with single button click". Can anyone tell me how to achieve this? I have attached the screenshot of my windows form.
I am using VB.NET 2010 and SQL SERVER 2008.
Thanks
Currently i am working with Datagrid. I want to move the data from one datagrid to another. I can populate the data in datagrid using combo box. Now i am stuck with how to move the data between datagrid and save the data using save button.
I following code till now which is working correctly:
VB.NET:
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Public Class gridview_search
Dim sqlFunc As New SQLConnectionNET.SQLConnection
Dim sINIFile As String = Application.StartupPath + "\DBConnection.INI"
Dim SQLCOnn As OleDbConnection = New OleDbConnection
Dim ds As DataSet = New DataSet
Private Sub gridview_search_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
SQLCOnn.Close()
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
ds.Clear()
SQLCOnn.Close()
'Retrieve value of Combo box from DB
LoadCountry()
LoadCountry2()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub LoadCountry()
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
Try
Dim query As String = "SELECT * FROM dbo.Cbr_CountryList WHERE CnlIsDefault = 1"
Dim myCommand As New OleDbCommand(query, SQLCOnn)
myCommand.CommandType = CommandType.Text
Dim dataAdapter As New OleDbDataAdapter(myCommand)
Dim dataTable As New DataTable()
dataAdapter.Fill(dataTable)
ComboBox2.DataSource = dataTable
ComboBox2.DisplayMember = "cnlCountryName"
ComboBox2.ValueMember = "cnlCountryID"
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub LoadCountry2()
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
Try
Dim query As String = "SELECT * FROM dbo.Cbr_CountryList WHERE CnlIsDefault = 1"
Dim myCommand As New OleDbCommand(query, SQLCOnn)
myCommand.CommandType = CommandType.Text
Dim dataAdapter As New OleDbDataAdapter(myCommand)
Dim dataTable As New DataTable()
dataAdapter.Fill(dataTable)
ComboBox3.DataSource = dataTable
ComboBox3.DisplayMember = "cnlCountryName"
ComboBox3.ValueMember = "cnlCountryID"
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub LoadDistrict(selectedValue As String)
If SQLCOnn.State = ConnectionState.Closed Then
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
End If
Try
Dim query As String = "select * from dbo.Cbr_DistrictList where CdlCountryId = '" & selectedValue & "'"
Dim myCommand As New OleDbCommand(query, SQLCOnn)
myCommand.CommandType = CommandType.Text
Dim dataAdapter As New OleDbDataAdapter(myCommand)
Dim dataTable As New DataTable()
dataAdapter.Fill(dataTable)
ComboBox1.DataSource = dataTable
ComboBox1.DisplayMember = "CdlDistrictName"
ComboBox1.ValueMember = "CdlDistrictID"
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub LoadDistrict2(selectedValue As String)
If SQLCOnn.State = ConnectionState.Closed Then
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
End If
Try
Dim query As String = "select * from dbo.Cbr_DistrictList where CdlCountryId = '" & selectedValue & "'"
Dim myCommand As New OleDbCommand(query, SQLCOnn)
myCommand.CommandType = CommandType.Text
Dim dataAdapter As New OleDbDataAdapter(myCommand)
Dim dataTable As New DataTable()
dataAdapter.Fill(dataTable)
ComboBox4.DataSource = dataTable
ComboBox4.DisplayMember = "CdlDistrictName"
ComboBox4.ValueMember = "CdlDistrictID"
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub LoadSubDistrict(selectedValue As String)
If SQLCOnn.State = ConnectionState.Closed Then
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
End If
Try
Dim adp As OleDbDataAdapter = New OleDbDataAdapter _
("select * from dbo.Cbr_SubDistrictList where SdlDistrictID = '" & selectedValue & "'", SQLCOnn)
Dim ds As DataSet = New DataSet()
adp.Fill(ds)
gvList.DataSource = ds.Tables(0)
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub LoadSubDistrict2(selectedValue As String)
If SQLCOnn.State = ConnectionState.Closed Then
SQLCOnn.ConnectionString = sqlFunc.GetConnectionString(sINIFile)
SQLCOnn.Open()
End If
Try
Dim adp As OleDbDataAdapter = New OleDbDataAdapter _
("select * from dbo.Cbr_SubDistrictList where SdlDistrictID = '" & selectedValue & "'", SQLCOnn)
Dim ds As DataSet = New DataSet()
adp.Fill(ds)
gvList2.DataSource = ds.Tables(0)
SQLCOnn.Close()
Catch ex As Exception
MessageBox.Show("Error No : " & Err.Number & vbCrLf _
& "Error : " & ex.Message & vbCrLf _
& "Source : " & Err.Source & vbCrLf _
, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
SQLCOnn.Close()
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim selectedValue As String
selectedValue = ComboBox1.SelectedValue.ToString()
LoadSubDistrict(selectedValue)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim selectedValue As String
selectedValue = ComboBox2.SelectedValue.ToString()
LoadDistrict(selectedValue)
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim selectedValue As String
selectedValue = ComboBox3.SelectedValue.ToString()
LoadDistrict2(selectedValue)
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox4.SelectedIndexChanged
Dim selectedValue As String
selectedValue = ComboBox4.SelectedValue.ToString()
LoadSubDistrict2(selectedValue)
End Sub
End Class
Till now its fine. Now what i want in my project is, "i want to move the data from one datagrid to another datagrid after loading the data to datagrid with single button click". Can anyone tell me how to achieve this? I have attached the screenshot of my windows form.
I am using VB.NET 2010 and SQL SERVER 2008.
Thanks