Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Windows application

$
0
0

Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Windows.Forms Imports System.Data.SqlClient Imports System.Configuration Imports System.Data.Odbc Imports System.Data.Common.DbCommandBuilder Public Class insert_update_delete Public cn As OdbcConnection = Nothing Private da As OdbcDataAdapter = Nothing Private cb As OdbcCommandBuilder = Nothing Private dt As DataTable = Nothing Private bindingSource As BindingSource = Nothing Private str As [String] = Nothing Public i As String Dim lst As New List(Of Class1)() Private Sub binddata() cn = New OdbcConnection("DSN=EDIXfer") 'Configuration.ConfigurationSettings.AppSettings("constr") str = "SELECT * FROM ETAProcessSchedule" da = New OdbcDataAdapter(str, cn) cb = New OdbcCommandBuilder(da) dt = New DataTable() da.Fill(dt) bindingSource = New BindingSource() bindingSource.DataSource = dt DataGridView1.DataSource = bindingSource DataGridView1.Columns(3).ReadOnly = True DataGridView1.Columns(4).ReadOnly = True DataGridView1.Columns(5).ReadOnly = True DataGridView1.Columns(6).ReadOnly = True DataGridView1.Columns(7).ReadOnly = True DataGridView1.Columns(8).ReadOnly = True DataGridView1.Columns(10).ReadOnly = True DataGridView1.Columns(11).ReadOnly = True DataGridView1.Columns(12).ReadOnly = True DataGridView1.Columns(13).ReadOnly = True DataGridView1.Columns(14).ReadOnly = True DataGridView1.Columns(15).ReadOnly = True DataGridView1.Columns(16).ReadOnly = True DataGridView1.Columns(17).ReadOnly = True DataGridView1.Columns(18).ReadOnly = True End Sub Private Sub insert_update_delete_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DataGridView2.Visible = False Button5.Visible = False Button6.Visible = False Button7.Visible = False Button8.Visible = False binddata() End Sub Dim ls As ArrayList = New ArrayList() Dim ss As Integer = 0 Dim ss1 As Integer = 0 Dim ssp As Integer = 1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim result As Integer = MessageBox.Show("are u sure ? do you want to delete the recoed", "Record Delete ", MessageBoxButtons.YesNo) If result = DialogResult.Yes Then DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index) MessageBox.Show("Record Deleted from GUI Only") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click MessageBox.Show("Record Inserted Successfully IN GUI Only") End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click da.Update(dt) binddata() MessageBox.Show("Record Updated Successfully In Database") End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Button1.Visible = False Button2.Visible = False Button3.Visible = False Button4.Visible = False DataGridView2.Visible = True Button5.Visible = True Button6.Visible = True Button7.Visible = True Button8.Visible = True i = DataGridView1.CurrentRow.Cells(0).Value.ToString() Dim sql As String = "select * from ProcessSchedule where EDIScheduleID='" + i + "'" Dim adp As New OdbcDataAdapter(sql, cn) Dim dt As DataTable = New System.Data.DataTable() adp.Fill(dt) Dim stp As String = dt.Rows(0)(21).ToString() Dim stp1 As String() = stp.Split(" "c) ls.Clear() lst.Clear() For x As Integer = 0 To stp1.Length - 1 ls.Add(stp1(x).ToString()) Next For x As Integer = 0 To ls.Count - 1 Dim ssttt As String = ls(x).ToString() Dim sssp As String() = ssttt.Split("="c) For x1 As Integer = 1 To sssp.Length - 1 ss = 0 ss1 = ssp Dim cs As New Class1() With { _ .VALUES = sssp(ss), _ .KEYS = sssp(x1).ToString() _ } lst.Add(cs) Next Next DataGridView2.DataSource = lst.ToList() DataGridView2.Refresh() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim value As String = Nothing Dim keys As String = Nothing Dim query As String = Nothing Dim str As String = Nothing For i As Integer = 0 To DataGridView2.Rows.Count - 1 value = DataGridView2.Rows(i).Cells(0).Value.ToString() keys = DataGridView2.Rows(i).Cells(1).Value.ToString() Dim ss As String = value + "="c + keys str += ss & Convert.ToString(" "c) Next query = "update ProcessSchedule set ProcParameters='" + str + "' where EDIScheduleID='" + i + "'" da = New OdbcDataAdapter(query, cn) dt = New DataTable() da.Fill(dt) MessageBox.Show("Data Updated In Database Successfully") binddata() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click DataGridView2.Visible = False Button5.Visible = False Button6.Visible = False Button1.Visible = True Button2.Visible = True Button3.Visible = True Button4.Visible = True Button7.Visible = False Button8.Visible = False End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim ss As Integer = Convert.ToInt32(DataGridView2.CurrentCell.RowIndex) lst.RemoveAt(ss) DataGridView2.DataSource = lst.ToList() DataGridView2.Refresh() End Sub Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Dim cs As New Class1() With {.VALUES = "", .KEYS = "".ToString()} lst.Add(cs) DataGridView2.DataSource = lst.ToList() DataGridView2.Refresh() End Sub End Class

This code is working fine with user dsn but in system dsn,data is not binding in grid view.

kindly help me out




Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>