Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,030

HOME > .NET Framework > Forum > ช่วยดู codeให้หน่อยได้ไหมครับ พอดีผมกด updateไปแล้วมันไปอัพเดทค่าทั้งtables เลยครับ



 

ช่วยดู codeให้หน่อยได้ไหมครับ พอดีผมกด updateไปแล้วมันไปอัพเดทค่าทั้งtables เลยครับ

 



Topic : 079450



โพสกระทู้ ( 29 )
บทความ ( 0 )



สถานะออฟไลน์




รบกวนหน่อยนะครับพอดีผมกด update ไปเเล้วมันไปอัพทั้งตารางผมเลยครับ พอดีลองทำการupdate stock ขอบคุณครับ

Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Partial Class web_Admininvent
    Inherits System.Web.UI.Page
    Dim conn As SqlConnection
    Dim cons As String = Class1.Constr3
    Dim DA As SqlDataAdapter
    Dim DS As DataSet
    Dim DT As DataTable
    Dim DV As DataView
    Dim com As SqlCommand
    Public iRow As Integer

    Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
        If Not Page.IsPostBack Then
            ViewState("Sortfiled") = "equip_id"
            ViewState("Sortdirection") = "asc"
            Me.ProductData()
            Me.MyGridBy()
        Else
            DV = Session("data")
            MyGridBy()
        End If
    End Sub
    Private Sub MyGridBy()
        GridView1.DataSource = DV
        Dim X1() As String = {"equip_id"}
        GridView1.DataKeyNames = X1
        GridView1.DataBind()
    End Sub
    Private Sub productdata(Optional ByVal equip_name As String = "")
        Dim sql2 As String = "SELECT * FROM productin"
        If equip_name <> "" Then
            sql2 &= " WHERE equip_name LIKE '" & equip_name & "%'"
            Me.MyGridBy()
        End If
        DA = New SqlDataAdapter(sql2, cons)
        Dim DT2 As New DataTable
        DA.Fill(DT2)

        'DT2.Columns.Add("Amount", GetType(Double), "Unitprice * UnitsInStock")
        DV = DT2.DefaultView
        'DV.Sort = "[" & ViewState("Sortfield") & "] " & ViewState("Sortdirection")
        Session("data") = DV
        MyGridBy()
    End Sub
    Public Sub dropemp()
        Dim sql2 As String = "SELECT emp_name FROM employ"
        DA = New SqlDataAdapter(sql2, cons)
        Dim dt As New DataTable
        Conn = New SqlConnection(cons)
        Conn.Open()
        DA.Fill(dt)

        DA = Nothing
        Conn.Close()
        Conn = Nothing

        '*** DropDownlist ***'
        With Me.DDEMP
            .DataSource = dt
            .DataTextField = "emp_name"
            .DataValueField = "emp_name"
            .DataBind()
        End With
        'Return DropDownList4
    End Sub
    Public Sub droppro()
        Dim sql2 As String = "SELECT code_equip FROM productstock"
        DA = New SqlDataAdapter(sql2, cons)
        Dim dt As New DataTable
        conn = New SqlConnection(cons)
        conn.Open()
        DA.Fill(dt)

        DA = Nothing
        Conn.Close()
        Conn = Nothing

        '*** DropDownlist ***'
        With Me.DDPRO
            .DataSource = dt
            .DataTextField = "code_equip"
            .DataValueField = "code_equip"
            .DataBind()
        End With
        'Return DropDownList4
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label19.Text = Date.Today
        TextBox17.Visible = False
        DDEMP.Visible = False
        Button7.Visible = False
        If Not Page.IsPostBack() Then
            droppro()
            dropemp()
            MyGridBy()
            showpro()
            'checkstock()
        Else
            Me.MyGridBy()
        End If
    End Sub
    Private Sub showpro()
        Dim sql2 As String = "SELECT * FROM productstock WHERE code_equip = '" & DDPRO.SelectedValue & "'"
        DA = New SqlDataAdapter(sql2, cons)
        Dim dt As New DataTable
        conn = New SqlConnection(cons)
        conn.Open()
        DA.Fill(dt)

        DA = Nothing
        conn.Close()
        conn = Nothing
        If dt.Rows.Count <> 0 Then
            Me.TextBox11.Text = dt.Rows(0)("equip_cate")
            Me.TextBox12.Text = dt.Rows(0)("equip_name")
            Me.TextBox14.Text = dt.Rows(0)("Brand")
            Me.TextBox15.Text = dt.Rows(0)("equip_model")
            Me.TextBox2.Text = dt.Rows(0)("equip_cost")
            Me.TextBox19.Text = dt.Rows(0)("amount_stock")
            Me.TextBox10.Text = dt.Rows(0)("equip_detail")
            Me.TextBox18.Text = dt.Rows(0)("emp_name")
            MyGridBy()
        End If
    End Sub
    'Private Sub checkstock()
    '    Dim Sql2 As String = "SELECT * FROM productstock WHERE code_equip = '" & DDPRO.SelectedValue & "'"
    '    DA = New SqlDataAdapter(sql2, cons)
    '    Dim dt As New DataTable
    '    conn = New SqlConnection(cons)
    '    conn.Open()
    '    DA.Fill(dt)

    '    DA = Nothing
    '    conn.Close()
    '    conn = Nothing
    '    If dt.Rows(0)("amount_stock") <= 2 Then
    '        Label29.Text = "จำนวนอุปกรณ์ไม่พอเบิก"
    '        Label29.ForeColor = Drawing.Color.Red
    '    Else
    '        Label29.Text = ""
    '    End If
    'End Sub
    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox10.Text = ""
        TextBox11.Text = ""
        TextBox12.Text = ""
        TextBox14.Text = ""
        TextBox15.Text = ""
        TextBox17.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox18.Text = ""
        TextBox19.Text = ""
        TextBox18.Visible = False
        DDPRO.Visible = False
        TextBox17.Visible = True
        Button6.Enabled = False
        Button5.Visible = True
        Button7.Visible = True
        DDEMP.Visible = True
        TextBox19.Enabled = False
        MyGridBy()
    End Sub

    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
        'Dim num1, num2, total As Integer
        'num1 = TextBox3.Text
        'num2 = TextBox19.Text
        'TextBox20.Text = total
        'total = num1 + num2
        TextBox19.Text = Val(TextBox3.Text) + Val(TextBox19.Text)
        Dim Conn As New SqlConnection(cons)
        If Page.IsPostBack Then
            Conn.Open()
            If TextBox17.Text <> "" Then
                Dim Sql2 As String = "insert into productin (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_in,emp_name) VALUES ('" & Label19.Text & "','" & TextBox17.Text & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
                Dim Sql3 As String = "insert into productstock (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_stock,emp_name) VALUES ('" & Label19.Text & "','" & TextBox17.Text & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
                Dim command As New SqlCommand(Sql2)
                Dim command2 As New SqlCommand(Sql3)

                command.Connection = Conn
                command.ExecuteNonQuery()
                command2.Connection = Conn
                command2.ExecuteNonQuery()
                GridView1.DataBind()
                Conn.Close()
                TextBox10.Text = ""
                TextBox11.Text = ""
                TextBox12.Text = ""
                TextBox14.Text = ""
                TextBox15.Text = ""
                TextBox17.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox18.Text = ""
                TextBox19.Text = ""
                DDPRO.Visible = True
                TextBox17.Visible = False
                Button6.Enabled = True
                Label29.Text = "บันทึกข้อมูลเรียบร้อย"
                Label29.ForeColor = Drawing.Color.Red
                Response.Redirect("AdminProductin.aspx")
            End If
            If TextBox17.Text = "" Then
                Dim DRV As DataRowView = DV(iRow)
                Dim Sql2 As String = "insert into productin (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_in,emp_name) VALUES ('" & Label19.Text & "','" & DDPRO.SelectedValue & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
                Dim Sql3 As String = "update productstock set date_in = @P1,code_equip = @P2,equip_name = @P3,Brand = @P4,equip_cate = @P5,equip_detail = @P6,equip_model = @P7,equip_cost = @P8,amount_stock = @P9,emp_name = @P10"
                Dim command As New SqlCommand(Sql2)
                Dim command2 As New SqlCommand(Sql3)

                Dim P1 As SqlParameter
                P1 = New SqlParameter("@P1", Label19.Text)
                command2.Parameters.Add(P1)

                Dim P2 As SqlParameter
                P2 = New SqlParameter("@P2", DDPRO.SelectedValue)
                command2.Parameters.Add(P2)

                Dim P3 As SqlParameter
                P3 = New SqlParameter("@P3", TextBox12.Text)
                command2.Parameters.Add(P3)

                Dim P4 As SqlParameter
                P4 = New SqlParameter("@P4", TextBox14.Text)
                command2.Parameters.Add(P4)

                Dim P5 As SqlParameter
                P5 = New SqlParameter("@P5", TextBox11.Text)
                command2.Parameters.Add(P5)

                Dim P6 As SqlParameter
                P6 = New SqlParameter("@P6", TextBox10.Text)
                command2.Parameters.Add(P6)

                Dim P7 As SqlParameter
                P7 = New SqlParameter("@P7", TextBox15.Text)
                command2.Parameters.Add(P7)

                Dim P8 As SqlParameter
                P8 = New SqlParameter("@P8", TextBox2.Text)
                command2.Parameters.Add(P8)

                Dim P9 As SqlParameter
                P9 = New SqlParameter("@P9", TextBox19.Text)
                command2.Parameters.Add(P9)

                Dim P10 As SqlParameter
                P10 = New SqlParameter("@P10", DDEMP.SelectedValue)
                command2.Parameters.Add(P10)

                command.Connection = Conn
                command.ExecuteNonQuery()
                command2.Connection = Conn
                command2.ExecuteNonQuery()
                GridView1.DataBind()
                Conn.Close()
                TextBox10.Text = ""
                TextBox11.Text = ""
                TextBox12.Text = ""
                TextBox14.Text = ""
                TextBox15.Text = ""
                TextBox17.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox18.Text = ""
                TextBox19.Text = ""
                DDPRO.Visible = True
                TextBox17.Visible = False
                Button6.Enabled = True
                Label29.Text = "บันทึกข้อมูลเรียบร้อย"
                Label29.ForeColor = Drawing.Color.Red
                Response.Redirect("AdminProductin.aspx")
                TextBox10.Text = ""
                TextBox11.Text = ""
                TextBox12.Text = ""
                TextBox14.Text = ""
                TextBox15.Text = ""
                TextBox17.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox18.Text = ""
                TextBox19.Text = ""
                DDPRO.Visible = True
                TextBox17.Visible = False
                Button6.Enabled = True
            End If
        End If
    End Sub

    Protected Sub DDPRO_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDPRO.SelectedIndexChanged
        showpro()
        'checkstock()
        MyGridBy()
        Label29.Text = DDPRO.SelectedValue
    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        Me.MyGridBy()
    End Sub

    Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        If ViewState("Sortfield") = e.SortExpression Then
            If ViewState("Sortdirection") = "asc" Then ViewState("Sortdirection") = "desc" Else ViewState("Sortdirection") = "asc"
        Else
            ViewState("Sortfield") = e.SortExpression
            ViewState("Sortdirection") = "asc"
        End If
        DV.Sort = "[" & ViewState("Sortfield") & "] " & ViewState("Sortdirection")
        Me.MyGridBy()

    End Sub

    Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Page.IsPostBack Then
            TextBox10.Text = ""
            TextBox11.Text = ""
            TextBox12.Text = ""
            TextBox14.Text = ""
            TextBox15.Text = ""
            TextBox17.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox18.Text = ""
            TextBox19.Enabled = True
            Button7.Visible = False
            DDPRO.Visible = True
            TextBox17.Visible = False
            Button6.Enabled = True
            showpro()

        End If
    End Sub
End Class





Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-06-06 21:07:14 By : benzdmax View : 978 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ตรง update คุณไม่ WHERE ล่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-06 21:10:36 By : mr.win
 


 

No. 2



โพสกระทู้ ( 29 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับพี่วินจะลองตรวจสอบดูนะครับ 555 ไม่รอบคอบเลยผม พี่มาช่วยผมหลายรอบเลย ขอบคุณมากๆครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-06 21:12:22 By : benzdmax
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดู codeให้หน่อยได้ไหมครับ พอดีผมกด updateไปแล้วมันไปอัพเดทค่าทั้งtables เลยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่