กระดานแสดงความคิดเห็น
Home
Contents
Articles
Quiz
Members
Sponsor
Print-friendly
MENU
ปรับปรุง : 2566-10-15 (กระดานแสดงความคิดเห็น)
เว็บเพจหน้านี้สำหรับผู้ดูแลเท่านั้น
รหัส secure
=>
นำตัวอักษร สีขาวบนพื้นแดง มาป้อนในช่องนี้
edit_topic_password =>
<center><table width=90% border=0 bgcolor=#000080><tr><td><font color=white size=4>vb.net gridview กับ update โดย อ.ธนัท ผุดกระจ่าง</td></tr></table><table width=90% bordercolor=#000080 border=1><tr><td bgcolor=white><br>เรียนกันทั้งวันเลยครับ กับโปรแกรมนี้<br /> อ.ธนัท ผุดกระจ่าง เป็นโปรแกรมเมอร์อยู่ toshiba<br /> =====================<br /> Imports System<br /> Imports System.Data<br /> Imports System.Data.SqlClient<br /> Partial Class Default2<br /> Inherits System.Web.UI.Page<br /> Dim mydts As New DataSet<br /> Dim mydtsd As New DataSet<br /> Dim myclasscnn As New ctlconnection<br /> Dim mytbname As String = "orders"<br /> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br /> Me.Page.MaintainScrollPositionOnPostBack = True<br /> TextBox1.Text = Request.QueryString("customerid")<br /> If TextBox1.Text = "" Then TextBox1.Text = "ANTON"<br /> Call loaddata1(TextBox1.Text)<br /> GridView1.DataSource = mydts<br /> GridView1.DataMember = mytbname<br /> GridView1.DataBind()<br /> ' Call loaddata2(10250)<br /> ' GridView2.DataSource = mydtsd<br /> ' GridView2.DataMember = "order details"<br /> ' GridView2.DataBind()<br /> End Sub<br /> <br /> Private Sub loaddata1(ByVal x As String)<br /> Dim mycmd As New SqlCommand<br /> mycmd = fnccmdorderlist("customerid", x)<br /> mydts = myclasscnn.fncreaddata(mydts, mycmd, mytbname)<br /> End Sub<br /> Private Sub loaddata2(ByVal x As Integer)<br /> Dim mycmd2 As New SqlCommand<br /> mycmd2 = fnccmdorderdlist("orderid", x)<br /> mydtsd = myclasscnn.fncreaddata(mydtsd, mycmd2, "order details")<br /> GridView2.DataSource = mydtsd<br /> GridView2.DataMember = "order details"<br /> GridView2.DataBind()<br /> End Sub<br /> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br /> Call loaddata1(TextBox1.Text)<br /> GridView1.DataSource = mydts<br /> GridView1.DataMember = mytbname<br /> GridView1.DataBind()<br /> End Sub<br /> <br /> Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged<br /> Dim myrow As Integer = GridView1.SelectedIndex<br /> Dim grdvrow As GridViewRow = GridView1.Rows(myrow)<br /> Dim mylinkbutton As LinkButton = CType(grdvrow.FindControl("linkbutton1"), LinkButton)<br /> Dim myorderid As Integer = CInt(mylinkbutton.Text)<br /> 'Response.Redirect("default2.aspx?customerid=" & mycustomerid)<br /> Session("myorderid") = myorderid<br /> Call loaddata2(myorderid)<br /> <br /> End Sub<br /> <br /> Protected Sub GridView2_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView2.RowCancelingEdit<br /> GridView2.EditIndex = -1<br /> loaddata2(CInt(Session("myorderid")))<br /> End Sub<br /> <br /> Protected Sub GridView2_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView2.RowDeleting<br /> Dim myrow As Integer = e.RowIndex<br /> Dim mydatarow As GridViewRow = GridView2.Rows(myrow)<br /> Dim myorderid As Integer = CInt(CType(mydatarow.FindControl("lblorderid"), Label).Text)<br /> Dim myproductid As String = CType(mydatarow.FindControl("lblproductid"), Label).Text<br /> Dim myquantity As Integer = 0<br /> Dim myResult As Integer = Nothing<br /> myResult = fncdel(myorderid, myproductid, myquantity)<br /> If myResult = Nothing Then<br /> Me.Response.Write("<script>alert('aa')</script>")<br /> End If<br /> 'Dim myresunt = fncx<br /> loaddata2(myorderid)<br /> GridView2.EditIndex = -1<br /> GridView2.DataBind()<br /> End Sub<br /> Private Sub mydelete(ByVal p1 As GridViewRow)<br /> <br /> End Sub<br /> <br /> Protected Sub GridView2_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing<br /> Dim myrow As Integer = e.NewEditIndex<br /> loaddata2(CInt(Session("myorderid")))<br /> GridView2.EditIndex = myrow<br /> GridView2.DataBind()<br /> End Sub<br /> <br /> Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating<br /> ' GridView2.Rows(e.RowIndex).Cells(0).Text = "a"<br /> Dim myrow As Integer = e.RowIndex<br /> Dim mydatarow As GridViewRow = GridView2.Rows(myrow)<br /> Dim myorderid As Integer = CInt(CType(mydatarow.FindControl("txtorderid"), TextBox).Text)<br /> Dim myproductid As String = CType(mydatarow.FindControl("txtproductid"), TextBox).Text<br /> Dim myquantity As String = CDbl(CType(mydatarow.FindControl("txtquantity"), TextBox).Text)<br /> Dim myResult As Integer = Nothing<br /> myResult = fncx(myorderid, myproductid, myquantity)<br /> If myResult = Nothing Then<br /> Me.Response.Write("<script>alert('aa')</script>")<br /> End If<br /> 'Dim myresunt = fncx<br /> loaddata2(myorderid)<br /> GridView2.EditIndex = -1<br /> GridView2.DataBind()<br /> End Sub<br /> <br /> <br /> <br /> Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)<br /> For Each myrow As GridViewRow In GridView2.Rows<br /> Dim mycheckbox As CheckBox = CType(myrow.FindControl("chkdelete"), CheckBox)<br /> Dim myproductid As String = CType(myrow.FindControl("lblproductid"), Label).Text<br /> Dim myorderid As Integer = CInt(CType(myrow.FindControl("lblorderid"), Label).Text)<br /> Dim myquantity As Integer = 0<br /> If mycheckbox.Checked = True Then<br /> Dim myResult As Integer = Nothing<br /> myResult = fncdel(myorderid, myproductid, myquantity)<br /> End If<br /> Next<br /> loaddata2(CInt(Session("myorderid")))<br /> GridView2.EditIndex = -1<br /> GridView2.DataBind()<br /> End Sub<br /> End Class<br /> <br /> ================<br /> Imports System<br /> Imports System.Data.SqlClient<br /> Imports Microsoft.VisualBasic<br /> <br /> Public Module ctrlquery<br /> Dim myclasscnn As New ctlconnection<br /> Public Function fnccmdcustomerlist(ByVal p1 As String, ByVal p2 As String) As SqlCommand<br /> Dim mycmd As New SqlCommand<br /> If p1 = "" Then p1 = "customerid"<br /> mycmd.Connection = myclasscnn.fncrtconnect<br /> mycmd.CommandText = "select * from northwind.dbo.customers where " & p1 & " like (@customerid)"<br /> 'mycmd.CommandText = "select * from northwind.dbo.customers"<br /> mycmd.CommandType = Data.CommandType.Text<br /> mycmd.Parameters.Add("@customerid", Data.SqlDbType.VarChar).Value = "%" & p2 & "%"<br /> ' mycmd.ExecuteNonQuery()<br /> Return mycmd<br /> End Function<br /> Public Function fnccmdorderlist(ByVal p1 As String, ByVal p2 As String) As SqlCommand<br /> Dim mycmd As New SqlCommand<br /> If p1 = "" Then p1 = "customerid"<br /> mycmd.Connection = myclasscnn.fncrtconnect<br /> mycmd.CommandText = "select * from northwind.dbo.orders where " & p1 & " like (@customerid)"<br /> 'mycmd.CommandText = "select * from northwind.dbo.customers"<br /> mycmd.CommandType = Data.CommandType.Text<br /> mycmd.Parameters.Add("@customerid", Data.SqlDbType.VarChar).Value = "%" & p2 & "%"<br /> ' mycmd.ExecuteNonQuery()<br /> Return mycmd<br /> End Function<br /> Public Function fnccmdorderdlist(ByVal p1 As String, ByVal p2 As Integer) As SqlCommand<br /> Dim mycmd As New SqlCommand<br /> If p1 = "" Then p1 = "orderid"<br /> mycmd.Connection = myclasscnn.fncrtconnect<br /> mycmd.CommandText = "select * from northwind.dbo.[order details] where " & p1 & " like (@orderid)"<br /> 'mycmd.CommandText = "select * from northwind.dbo.customers"<br /> mycmd.CommandType = Data.CommandType.Text<br /> mycmd.Parameters.Add("@orderid", Data.SqlDbType.Int).Value = p2<br /> ' mycmd.ExecuteNonQuery()<br /> Return mycmd<br /> End Function<br /> Public Function fncx(ByVal p1 As Integer, ByVal p2 As Integer, ByVal p3 As Double) As Integer<br /> Dim mycmd As New SqlCommand<br /> Dim myresult As Integer = Nothing<br /> Try<br /> With mycmd<br /> .Connection = myclasscnn.fncrtconnect<br /> .Connection.Open()<br /> .CommandTimeout = 0<br /> .CommandText = "update northwind.dbo.[order details] set quantity = @quantity where orderid = @orderid and productid = @productid "<br /> .CommandType = Data.CommandType.Text<br /> .Parameters.Add("@orderid", Data.SqlDbType.Decimal).Value = p1<br /> .Parameters.Add("@productid", Data.SqlDbType.Decimal).Value = p2<br /> .Parameters.Add("@quantity", Data.SqlDbType.Decimal).Value = p3<br /> myresult = .ExecuteNonQuery()<br /> .Connection.Close()<br /> End With<br /> Return myresult<br /> Catch ex As Exception<br /> Return Nothing<br /> End Try<br /> End Function<br /> Public Function fncdel(ByVal p1 As Integer, ByVal p2 As Integer, ByVal p3 As Double) As Integer<br /> Dim mycmd As New SqlCommand<br /> Dim myresult As Integer = Nothing<br /> Try<br /> With mycmd<br /> .Connection = myclasscnn.fncrtconnect<br /> .Connection.Open()<br /> .CommandTimeout = 0<br /> .CommandText = "delete from northwind.dbo.[order details] where orderid = @orderid and productid = @productid "<br /> .CommandType = Data.CommandType.Text<br /> .Parameters.Add("@orderid", Data.SqlDbType.Decimal).Value = p1<br /> .Parameters.Add("@productid", Data.SqlDbType.Decimal).Value = p2<br /> .Parameters.Add("@quantity", Data.SqlDbType.Decimal).Value = p3<br /> myresult = .ExecuteNonQuery()<br /> .Connection.Close()<br /> End With<br /> Return myresult<br /> Catch ex As Exception<br /> Return Nothing<br /> End Try<br /> End Function<br /> End Module<br /> <br /> <br><br></td></tr><tr><td align=right bgcolor=black><font color=white><small><b>จากคุณ :</b> บุรินทร์ <a href=mailto:></a><a title='202.29.78.18'>.</a><br> 06:13am (29/07/06)</font></td></tr></table></center>