Select Case status
Case "add"
s = ("INSERT Into Products(ProductID,ProductName,LastCost,CostAvg,SalePrice,Stock,Picture,UnitID,CategoryID,InOrder)")
s &= ("values(@proid,@proname,@lc,@Cagc,@price,@stock,@Pic,@uid,@cid,@In)")
Case "edit"
s = ("UPDATE Products ")
s &= ("Set ProductName = @proname, ")
s &= ("LastCost = @lc, ")
s &= ("CostAvg = @Cagc, ")
s &= ("SalePrice = @price, ")
s &= ("Stock = @stock, ")
s &= ("Picture = @Pic, ")
s &= ("UnitID = @uid,")
s &= ("CategoryID = @cid")
s &= ("InOrder = @In")
s &= ("WHERE (ProductID = @proid) ")
End Select
Dim cm As New SqlCommand
With cm
.CommandType = CommandType.Text
.CommandText = s
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@proid", SqlDbType.NVarChar, 10).Value = Txtid.Text.Trim()
.Parameters.Add("@proname", SqlDbType.NVarChar, 100).Value = Txtname.Text.Trim()
.Parameters.Add("@lc", SqlDbType.Float).Value = TxtLastcost.Text.Trim()
.Parameters.Add("@Cagc", SqlDbType.Float).Value = TxtLastcost.Text
.Parameters.Add("@price", SqlDbType.Float).Value = TxtPrice.Text.Trim()
.Parameters.Add("@stock", SqlDbType.Int).Value = Txtstock.Text.Trim()
.Parameters.Add("@Pic", SqlDbType.NVarChar, 100).Value = Picture1.ImageLocation
.Parameters.Add("@uid", SqlDbType.NVarChar, 10).Value = CbbUnit.SelectedValue()
.Parameters.Add("@cid", SqlDbType.NVarChar, 10).Value = CbbCategory.SelectedValue()
.Parameters.Add("@In", SqlDbType.Int).Value = 0
.ExecuteNonQuery()
MessageBox.Show("บันทึกเรียบร้อยแล้ว", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End With
FrmProduct_Load(sender, e)
Tag : .NET, Ms SQL Server 2005, VBScript, Win (Windows App), VB.NET
Date :
2012-02-28 14:10:58
By :
l3kaing
View :
1074
Reply :
3
No. 1
Guest
Select Case status
Case "add"
s = ("INSERT Into Products(ProductID,ProductName,LastCost,CostAvg,SalePrice,Stock,Picture,UnitID,CategoryID,InOrder)")
s &= ("values(@proid,@proname,@lc,@Cagc,@price,@stock,@Pic,@uid,@cid,@In)")
Case "edit"
s = ("UPDATE Products ")
s &= ("Set ProductName = @proname, ")
s &= ("LastCost = @lc, ")
s &= ("CostAvg = @Cagc, ")
s &= ("SalePrice = @price, ")
s &= ("Stock = @stock, ")
s &= ("Picture = @Pic, ")
s &= ("UnitID = @uid,")
s &= ("CategoryID = @cid")
s &= ("InOrder = @In")
s &= ("WHERE (ProductID = @proid) ")
End Select