|
|
|
อยากได้ตัวอย่างcode insert uadate ไฟล์รูปลง sql database อะคะ ใช้ vb2010 เขียน ไฟล์รูปรันมาจากbarcode picturebox |
|
|
|
|
|
|
|
Code (VB.NET)
Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
If (tbName.Text = "" Or cbbSup.Text = "-- กรุณาเลือกประเภทสินค้า --" Or cbbType.Text = "-- กรุณาเลือกประเภทสินค้า --" Or tbCost.Text = "" Or tbID.Text = "" Or tbSale.Text = "") Then
MessageBox.Show("กรุณากรอกข้อมูลให้ครบ !!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return
ElseIf CDbl(tbCost.Text) = 0 Or CDbl(tbCost.Text) = 0.0 Or CDbl(tbCost.Text) = 0.0 Then
MessageBox.Show("ราคาทุนไม่สามารเป็น '0' ได้ !!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return
ElseIf CDbl(tbSale.Text) = 0 Or CDbl(tbSale.Text) = 0.0 Or CDbl(tbSale.Text) = 0.0 Then
MessageBox.Show("ราคาขายไม่สามารเป็น '0' ได้ !!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return
End If
If CInt(tbCost.Text) > CInt(tbSale.Text) Then
MessageBox.Show("ราคาขายน้อยกว่าราคาทุน กรุณาใส่ราคาขายใหม่ !!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Stop)
tbSale.Focus()
Return
End If
If click = 1 Then
Dim sqlRate As String = "select rate from product_unit_detail where rate='1' and pro_id='" & tbID.Text & "'"
da = New SqlDataAdapter(sqlRate, Conn)
da.Fill(ds, "checkRate")
If ds.Tables("checkRate").Rows.Count = 0 Then
MessageBox.Show("กรุณาใส่หน่วยสินค้าหน่วยเล็ก !!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return
End If
End If
Dim sqlcheckPro As String = "select pro_ID from product where pro_ID ='" & tbID.Text & "'"
da = New SqlDataAdapter(sqlcheckPro, Conn)
da.Fill(ds, "checkPro")
If ds.Tables("checkPro").Rows.Count = 0 Then
Try
Dim sqlInsert As String = "insert into product (pro_id,pro_name,detail,balance,cost_price,sale_price,sup_id,cat_id,pro_status,barcode)"
sqlInsert &= "VALUES('" & tbID.Text & "',"
sqlInsert &= "'" & tbName.Text & "',"
sqlInsert &= "'" & tbDetail.Text & "',"
sqlInsert &= "'0',"
sqlInsert &= "'" & tbCost.Text & "',"
sqlInsert &= "'" & tbSale.Text & "',"
sqlInsert &= "'" & cbbSup.SelectedValue.ToString() & "',"
sqlInsert &= "'" & cbbType.SelectedValue.ToString() & "','0','0','1',"
sqlInsert &= "@barcode)"
Dim img As New SqlParameter("@barcode", SqlDbType.Image)
Dim ms As New MemoryStream()
PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arr As Byte() = ms.ToArray
Dim com As New SqlCommand(conStr, Conn)
img.Value = arr
com.Parameters.Add(img)
com.ExecuteNonQuery()
MessageBox.Show("บันทึกข้อมูลสินค้าเรียบร้อยแล้ว", "บันทึก", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "Insert")
End Try
Else
Try
Dim sqlEdit As String = "UPDATE product"
sqlEdit &= " SET pro_name ='" & tbName.Text & "',"
sqlEdit &= "detail ='" & tbDetail.Text & "',"
sqlEdit &= "balance='" & tbBal.Text & "',"
sqlEdit &= "cost_price='" & tbCost.Text & "',"
sqlEdit &= "sale_price='" & tbSale.Text & "',"
sqlEdit &= "sup_id='" & cbbSup.SelectedValue.ToString() & "',"
sqlEdit &= "cat_id='" & cbbType.SelectedValue.ToString() & "',"
' sqlEdit &= "expert_date='" & expert & "'"
sqlEdit &= " WHERE (pro_ID ='" & tbID.Text & "')"
Command(sqlEdit)
MessageBox.Show("แก้ไขข้อมูลเรียบร้อยแล้ว !!!", "ผลการแก้ไข", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch
MessageBox.Show("ไม่สามารถแก้ไขข้อมูลได้", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
End If
gvProduct.Enabled = True
tbID.Clear()
tbName.Clear()
tbBal.Clear()
tbCost.Clear()
tbDetail.Clear()
tbSale.Clear()
cbbSup.Text = "-- กรุณาเลือกบริษัทคู่ค้า --"
cbbType.Text = "-- กรุณาเลือกประเภทสินค้า --"
tbID.ReadOnly = False
tbName.ReadOnly = True
cbbSup.Enabled = False
cbbType.Enabled = False
tbCost.ReadOnly = True
tbSale.ReadOnly = True
tbBal.ReadOnly = True
tbDetail.ReadOnly = True
btAdd.Enabled = True
btEdit.Enabled = True
btDel.Enabled = True
btSave.Enabled = False
PictureBox1.Image = Nothing
ShowProduct()
End Sub
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x), Windows
|
|
|
|
|
|
Date :
2013-07-19 23:31:24 |
By :
Belletempo |
View :
977 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code ก็เขียนได้เยอะแล้วนี่ครับ ติดปัญหาตรงไหน
|
|
|
|
|
Date :
2013-07-20 07:54:07 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ตรงไหนคะ เฮ้อ งง
|
|
|
|
|
Date :
2013-07-21 00:13:58 |
By :
Belletempo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (VB.NET)
pro_id **** sqlInsert &= "VALUES('" & tbID.Text & "',"
,pro_name **** sqlInsert &= "'" & tbName.Text & "',"
,detail ***** sqlInsert &= "'" & tbDetail.Text & "',"
,balance **** sqlInsert &= "'0',"
,cost_price **** sqlInsert &= "'" & tbCost.Text & "',"
,sale_price **** sqlInsert &= "'" & tbSale.Text & "',"
,sup_id **** sqlInsert &= "'" & cbbSup.SelectedValue.ToString() & "',"
,cat_id ***** sqlInsert &= "'" & cbbType.SelectedValue.ToString() & "',
,pro_status *** '0',
,barcode **** '0',
**** '1',"
**** sqlInsert &= "@barcode)"
ทำไมมันเกินไปอ่า หรือผมเข้าใจอะไรผิดไป
|
|
|
|
|
Date :
2013-07-21 23:49:35 |
By :
poomzaa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|