thaiall logomy background

กระดานแสดงความคิดเห็น

my town
vb.net gridview กับ update โดย อ.ธนัท ผุดกระจ่าง
เรียนกันทั้งวันเลยครับ กับโปรแกรมนี้
อ.ธนัท ผุดกระจ่าง เป็นโปรแกรมเมอร์อยู่ toshiba
=====================
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Dim mydts As New DataSet
Dim mydtsd As New DataSet
Dim myclasscnn As New ctlconnection
Dim mytbname As String = "orders"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Page.MaintainScrollPositionOnPostBack = True
TextBox1.Text = Request.QueryString("customerid")
If TextBox1.Text = "" Then TextBox1.Text = "ANTON"
Call loaddata1(TextBox1.Text)
GridView1.DataSource = mydts
GridView1.DataMember = mytbname
GridView1.DataBind
' Call loaddata2(10250)
' GridView2.DataSource = mydtsd
' GridView2.DataMember = "order details"
' GridView2.DataBind End Sub

Private Sub loaddata1(ByVal x As String)
Dim mycmd As New SqlCommand
mycmd = fnccmdorderlist("customerid", x)
mydts = myclasscnn.fncreaddata(mydts, mycmd, mytbname)
End Sub
Private Sub loaddata2(ByVal x As Integer)
Dim mycmd2 As New SqlCommand
mycmd2 = fnccmdorderdlist("orderid", x)
mydtsd = myclasscnn.fncreaddata(mydtsd, mycmd2, "order details")
GridView2.DataSource = mydtsd
GridView2.DataMember = "order details"
GridView2.DataBind End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Call loaddata1(TextBox1.Text)
GridView1.DataSource = mydts
GridView1.DataMember = mytbname
GridView1.DataBind End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim myrow As Integer = GridView1.SelectedIndex
Dim grdvrow As GridViewRow = GridView1.Rows(myrow)
Dim mylinkbutton As LinkButton = CType(grdvrow.FindControl("linkbutton1"), LinkButton)
Dim myorderid As Integer = CInt(mylinkbutton.Text)
'Response.Redirect("default2.aspx?customerid=" & mycustomerid)
Session("myorderid") = myorderid
Call loaddata2(myorderid)

End Sub

Protected Sub GridView2_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView2.RowCancelingEdit
GridView2.EditIndex = -1
loaddata2(CInt(Session("myorderid")))
End Sub

Protected Sub GridView2_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView2.RowDeleting
Dim myrow As Integer = e.RowIndex
Dim mydatarow As GridViewRow = GridView2.Rows(myrow)
Dim myorderid As Integer = CInt(CType(mydatarow.FindControl("lblorderid"), Label).Text)
Dim myproductid As String = CType(mydatarow.FindControl("lblproductid"), Label).Text
Dim myquantity As Integer = 0
Dim myResult As Integer = Nothing
myResult = fncdel(myorderid, myproductid, myquantity)
If myResult = Nothing Then
Me.Response.Write("<script>alert('aa')</script>")
End If
'Dim myresunt = fncx
loaddata2(myorderid)
GridView2.EditIndex = -1
GridView2.DataBind End Sub
Private Sub mydelete(ByVal p1 As GridViewRow)

End Sub

Protected Sub GridView2_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing
Dim myrow As Integer = e.NewEditIndex
loaddata2(CInt(Session("myorderid")))
GridView2.EditIndex = myrow
GridView2.DataBind End Sub

Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating
' GridView2.Rows(e.RowIndex).Cells(0).Text = "a"
Dim myrow As Integer = e.RowIndex
Dim mydatarow As GridViewRow = GridView2.Rows(myrow)
Dim myorderid As Integer = CInt(CType(mydatarow.FindControl("txtorderid"), TextBox).Text)
Dim myproductid As String = CType(mydatarow.FindControl("txtproductid"), TextBox).Text
Dim myquantity As String = CDbl(CType(mydatarow.FindControl("txtquantity"), TextBox).Text)
Dim myResult As Integer = Nothing
myResult = fncx(myorderid, myproductid, myquantity)
If myResult = Nothing Then
Me.Response.Write("<script>alert('aa')</script>")
End If
'Dim myresunt = fncx
loaddata2(myorderid)
GridView2.EditIndex = -1
GridView2.DataBind End Sub



Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
For Each myrow As GridViewRow In GridView2.Rows
Dim mycheckbox As CheckBox = CType(myrow.FindControl("chkdelete"), CheckBox)
Dim myproductid As String = CType(myrow.FindControl("lblproductid"), Label).Text
Dim myorderid As Integer = CInt(CType(myrow.FindControl("lblorderid"), Label).Text)
Dim myquantity As Integer = 0
If mycheckbox.Checked = True Then
Dim myResult As Integer = Nothing
myResult = fncdel(myorderid, myproductid, myquantity)
End If
Next
loaddata2(CInt(Session("myorderid")))
GridView2.EditIndex = -1
GridView2.DataBind End Sub
End Class

================
Imports System
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Public Module ctrlquery
Dim myclasscnn As New ctlconnection
Public Function fnccmdcustomerlist(ByVal p1 As String, ByVal p2 As String) As SqlCommand
Dim mycmd As New SqlCommand
If p1 = "" Then p1 = "customerid"
mycmd.Connection = myclasscnn.fncrtconnect
mycmd.CommandText = "select * from northwind.dbo.customers where " & p1 & " like (@customerid)"
'mycmd.CommandText = "select * from northwind.dbo.customers"
mycmd.CommandType = Data.CommandType.Text
mycmd.Parameters.Add("@customerid", Data.SqlDbType.VarChar).Value = "%" & p2 & "%"
' mycmd.ExecuteNonQuery Return mycmd
End Function
Public Function fnccmdorderlist(ByVal p1 As String, ByVal p2 As String) As SqlCommand
Dim mycmd As New SqlCommand
If p1 = "" Then p1 = "customerid"
mycmd.Connection = myclasscnn.fncrtconnect
mycmd.CommandText = "select * from northwind.dbo.orders where " & p1 & " like (@customerid)"
'mycmd.CommandText = "select * from northwind.dbo.customers"
mycmd.CommandType = Data.CommandType.Text
mycmd.Parameters.Add("@customerid", Data.SqlDbType.VarChar).Value = "%" & p2 & "%"
' mycmd.ExecuteNonQuery Return mycmd
End Function
Public Function fnccmdorderdlist(ByVal p1 As String, ByVal p2 As Integer) As SqlCommand
Dim mycmd As New SqlCommand
If p1 = "" Then p1 = "orderid"
mycmd.Connection = myclasscnn.fncrtconnect
mycmd.CommandText = "select * from northwind.dbo.[order details] where " & p1 & " like (@orderid)"
'mycmd.CommandText = "select * from northwind.dbo.customers"
mycmd.CommandType = Data.CommandType.Text
mycmd.Parameters.Add("@orderid", Data.SqlDbType.Int).Value = p2
' mycmd.ExecuteNonQuery Return mycmd
End Function
Public Function fncx(ByVal p1 As Integer, ByVal p2 As Integer, ByVal p3 As Double) As Integer
Dim mycmd As New SqlCommand
Dim myresult As Integer = Nothing
Try
With mycmd
.Connection = myclasscnn.fncrtconnect
.Connection.Open .CommandTimeout = 0
.CommandText = "update northwind.dbo.[order details] set quantity = @quantity where orderid = @orderid and productid = @productid "
.CommandType = Data.CommandType.Text
.Parameters.Add("@orderid", Data.SqlDbType.Decimal).Value = p1
.Parameters.Add("@productid", Data.SqlDbType.Decimal).Value = p2
.Parameters.Add("@quantity", Data.SqlDbType.Decimal).Value = p3
myresult = .ExecuteNonQuery .Connection.Close End With
Return myresult
Catch ex As Exception
Return Nothing
End Try
End Function
Public Function fncdel(ByVal p1 As Integer, ByVal p2 As Integer, ByVal p3 As Double) As Integer
Dim mycmd As New SqlCommand
Dim myresult As Integer = Nothing
Try
With mycmd
.Connection = myclasscnn.fncrtconnect
.Connection.Open .CommandTimeout = 0
.CommandText = "delete from northwind.dbo.[order details] where orderid = @orderid and productid = @productid "
.CommandType = Data.CommandType.Text
.Parameters.Add("@orderid", Data.SqlDbType.Decimal).Value = p1
.Parameters.Add("@productid", Data.SqlDbType.Decimal).Value = p2
.Parameters.Add("@quantity", Data.SqlDbType.Decimal).Value = p3
myresult = .ExecuteNonQuery .Connection.Close End With
Return myresult
Catch ex As Exception
Return Nothing
End Try
End Function
End Module



จากคุณ : บุรินทร์ .
06:13am (29/07/06)
ทความเกี่ยวกับไอทีในชีวิตประจำวัน (Information Technology in Life) ถูกเขียนลงในหนังสือพิมพ์ฅนเมืองเหนือ เป็นหนังสือพิมพ์รายสัปดาห์ เริ่มเขียนปลายปีพ.ศ. 2549 จนถึงมิถุนายน พ.ศ.2560 รวมได้ 611 บทความมีโฮมเพจอยู่ที่ http://www.thaiall.com/itinlife และ http://www.thaiall.com/opinion เพื่อเป็นแหล่งแบ่งปันเรื่องราวที่ได้พบ ได้อ่าน ได้ปฏิบัติ แล้วนำมาเรียบเรียงแบ่งปันแก่เพื่อนชาวไทย และส่งให้กองบรรณาธิการนำไปตีพิมพ์ลงในหนังสือพิมพ์ท้องถิ่นของจังหวัดลำปาง
Opinion แปลว่า ความคิดเห็น วาทะ ความเชื่อ ที่สามารถสะท้อนออกมาให้อยู่ในรูปของวรรณกรรม หรืองานเขียน ที่เรื่องราวจะถูกร้อยเรียงเป็นตัวอักษร ไล่เรียงตามลำดับให้ได้รู้และเข้าใจความคิดความเห็น ที่ไม่เลือนหายไปตามเวลาเหมือนความทรงจำ
version 1.3 (15 ตุลาคม 2566)
Thaiall.com
Thaiall.com