Anda di halaman 1dari 5

Imports System.

Data
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton4 = New System.Windows.Forms.RadioButton
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit(
)
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 8)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(576, 136)
Me.DataGrid1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 336)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "create new datasheet"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(168, 336)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(104, 23)
Me.Button2.TabIndex = 2
Me.Button2.Text = "insert new records"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(288, 336)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(104, 23)
Me.Button3.TabIndex = 3
Me.Button3.Text = "retrieve records"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(416, 336)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 4
Me.Button4.Text = "update"
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(424, 152)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.TabIndex = 5
Me.RadioButton1.Text = "EXCELLENT"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(424, 200)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.TabIndex = 6
Me.RadioButton2.Text = "GOOD"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(176, 184)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 7
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(176, 232)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 8
Me.TextBox2.Text = ""
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(424, 240)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.TabIndex = 9
Me.RadioButton3.Text = "AVERAGE"
'
'RadioButton4
'
Me.RadioButton4.Location = New System.Drawing.Point(424, 288)
Me.RadioButton4.Name = "RadioButton4"
Me.RadioButton4.TabIndex = 10
Me.RadioButton4.Text = "POOR"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 184)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(144, 23)
Me.Label1.TabIndex = 11
Me.Label1.Text = "ENROLLMENT NUMBER"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(40, 232)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 12
Me.Label2.Text = "NAME"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(592, 374)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.RadioButton4)
Me.Controls.Add(Me.RadioButton3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.RadioButton2)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim Comm As New OleDb.OleDbCommand
Dim i As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even
tArgs) Handles MyBase.Load
ImportAttendence("c:\\feedback.xls")
End Sub
Public Function ImportAttendence(ByVal PrmPathExcelFile As String)
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft
.Jet.OLEDB.4.0; " & "data source=" & PrmPathExcelFile & "; " & "Extended Propert
ies=Excel 8.0;")
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Comm.Connection = MyConnection
Comm.CommandText = "Create Table Sheet1 (EnrollmentNo char(255), Student
Name char(255),Q1 integer,Q2 integer,Q3 integer,Q4 integer)"
Comm.CommandText = "Create Table chart1"
Try
MyConnection.Open()
Comm.ExecuteNonQuery()
MsgBox("Created.")
MyConnection.Close()
Catch ex As Exception
MsgBox("Error.")
MyConnection.Close()
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button2.Click
Comm.Connection = MyConnection
Dim ans As Integer
If RadioButton1.Checked = True Then
ans = 4
ElseIf RadioButton2.Checked = True Then
ans = 3
ElseIf RadioButton3.Checked = True Then
ans = 2
ElseIf RadioButton4.Checked = True Then
ans = 1
Else
MsgBox("select value")
End If
'For i = 5 To 14
Comm.CommandText = "Insert INTO [Sheet1$] (EnrollmentNo,StudentName,Q1)
Values (" & (TextBox1.Text.ToString) & ",'" & TextBox2.Text & "','" & ans.ToStri
ng & "')"
Try
MyConnection.Open()
Comm.ExecuteNonQuery()
MsgBox("Inserted.")
MyConnection.Close()
Catch ex As Exception
MsgBox("Error.")
MyConnection.Close()
End Try
'Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button3.Click
Try
Dim DtSet As New DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [s
heet1$]", MyConnection)
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MyConnection.Close()
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button4.Click
Dim Comm As New OleDb.OleDbCommand
Comm.Connection = MyConnection
Comm.CommandText = "Update [Sheet1$] SET F1 = 3 Where F2 = 'A'"
Try
MyConnection.Open()
Comm.ExecuteNonQuery()
MsgBox("Updated.")
MyConnection.Close()
Catch ex As Exception
MsgBox("Error.")
MyConnection.Close()
End Try
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As S
ystem.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class

Anda mungkin juga menyukai