Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt As DataTable
'*** DataSet To DataTable ***'
'dt = CreateDsToDt()
'*** DataTable ***'
'dt = CreateDataTable()
'*** DataSet ***'
dt = CreateDataSet.Tables(0) '*** Convert DataSet to DataTable ***'
'*** TableRows ***'
'dt = DataTableRows()
'*** BindData to GridView ***'
myGridView.DataSource = dt
myGridView.DataBind()
End Sub
'*** DataTable ***'
Function CreateDataTable() As DataTable
Dim objConn As New OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=MSDAORA;Data Source=prodorcl_new;User ID=bcs;password=password"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM COMPANY"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return dt '*** Return DataTable ***'
End Function
'*** DataSet ***'
Function CreateDataSet() As DataSet
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim strConnString, strSQL As String
strConnString = "Provider=MSDAORA;Data Source=prodorcl_new;User ID=bcs;password=password"
strSQL = "SELECT * FROM COMPANY"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
End Function
'*** DataSet To DataTable ***'
Function CreateDsToDt() As DataTable
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Provider=MSDAORA;Data Source=prodorcl_new;User ID=bcs;password=password"
strSQL = "SELECT * FROM COMPANY"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return dt '*** Return DataTable ***'
End Function
'*** TableRows (DataTable) ***'
Function DataTableRows() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
'*** Column ***'
dt.Columns.Add("COMP_CODE")
dt.Columns.Add("COMP_NAME")
dt.Columns.Add("COMP_ADDRESS1")
dt.Columns.Add("COMP_TEL")
dt.Columns.Add("COMP_FAX")
dt.Columns.Add("COMP_ID")
'*** Rows ***'
dr = dt.NewRow
dr("CustomerID") = ""
dr("Name") = ""
dr("Email") = ""
dr("CountryCode") = ""
dr("Budget") = ""
dr("Used") = ""
dt.Rows.Add(dr)
Return dt '*** Return DataTable ***'
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim sqlconn As New SqlClient.SqlConnection
Dim myCommand As New SqlCommand
Dim dt As New DataTable
Dim i As New Integer
For i = 0 To dt.Rows.Count - 1
Next
sqlconn.ConnectionString = "Data Source=BANK\SQLEXPRESS;Initial Catalog=HR;Integrated Security=True"
Try
Dim sql As String = ""
sql = "INSERT INTO COMP(COMP_ID,COMP_CODE,COMP_NAME,COMP_ADDRESS1,COMP_TEL,COMP_FAX)"
sql &= " VALUES('" & dt.Rows(i)("COMP_ID") & "',"
sql &= "'" & dt.Rows(i)("COMP_CODE") & "',"
sql &= "'" & dt.Rows(i)("COMP_NAME") & "',"
sql &= "'" & dt.Rows(i)("COMP_ADDRESS1") & "',"
sql &= "'" & dt.Rows(i)("COMP_TEL") & "',"
sql &= "'" & dt.Rows(i)("COMP_FAX") & "')"
With sqlconn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = sqlconn.ConnectionString
.Open()
End With
If MsgBox("ต้องการบันทึกข้อมูล", CType(vbQuestion + vbYesNo, MsgBoxStyle), "คำยืนยัน") = vbYes Then
End If
With myCommand
.CommandType = Data.CommandType.Text
.CommandText = sql
.Connection = sqlconn
.ExecuteNonQuery()
End With
If MsgBox("บันทึกฐานข้อมูลเรียบร้อยแล้ว", CType(vbOKOnly + vbOKOnly, MsgBoxStyle), "ผลการทำงาน") Then
End If
Catch ErrProcess As Exception
MsgBox("ไม่สามารถบันทึกได้", CType(vbCritical + vbOKOnly, MsgBoxStyle), "ผลการทำงาน")
Exit Sub
sqlconn.Close()
End Try
End Sub
End Class
Sub polctble(ByVal sqlp As String, ByVal crw As GridView)
Dim dsp As New DataSet()
Dim sqlDataAdapter As New SqlDataAdapter(sqlp, fRP_Conn)
sqlDataAdapter.Fill(dsp)
dsp.Tables(0).TableName = "Policy"
With crw
.DataSource = dsp.Tables("Policy")
.DataBind()
End With
Dim dview As Data.DataView
dview = dsp.Tables("Policy").DefaultView
Dim drow As Data.DataRowView
Dim j As Integer = 0
For Each drow In dview
Dim p As String
p = CStr(drow.Item("Payment_status"))
If p = "Y" Then
GridView_CLINT_EDIT.SelectedIndex = j
Dim CheckTrue As CheckBox = DirectCast(crw.SelectedRow.FindControl("ChStatus"), CheckBox)
CheckTrue.Checked = True
CheckTrue.Enabled = False
Else
GridView_CLINT_EDIT.SelectedIndex = j
Dim CheckTrue As CheckBox = DirectCast(crw.SelectedRow.FindControl("ChStatus"), CheckBox)
CheckTrue.Checked = False
CheckTrue.Enabled = True
End If
j = j + 1
Next
dsp = Nothing
Gr