Private Sub saveProduct()
Dim sqlProduct As String
sb = New StringBuilder
sb.Append("INSERT INTO product (code,group_id,name_thai,name_eng,sell_price,glass,is_available,created,images)")
sb.Append(" VALUES (@code,@group_id,@name_thai,@name_eng,@sell_price,@glass,@is_available,@created,@images)")
sqlProduct = sb.ToString
'--Period process
cmd = New SqlCommand
'Try
With cmd
.CommandText = sqlProduct
.Connection = conn
.Parameters.Add("@code", SqlDbType.VarChar).Value = txtCode.Text.Trim
.Parameters.Add("@group_id", SqlDbType.SmallInt).Value = cboGroup.SelectedValue
.Parameters.Add("@name_thai", SqlDbType.VarChar).Value = txtNameThai.Text.Trim
.Parameters.Add("@name_eng", SqlDbType.VarChar).Value = txtNameEng.Text.Trim
.Parameters.Add("@sell_price", SqlDbType.Decimal).Value = txtSell_Price.Text.Trim
.Parameters.Add("@glass", SqlDbType.SmallInt).Value = cboGlass.SelectedValue
.Parameters.Add("@is_available", SqlDbType.TinyInt).Value = "1"
.Parameters.Add("@created", SqlDbType.DateTime).Value = DateTime.Now
.Parameters.Add("@images", SqlDbType.Image).Value = File.ReadAllBytes(getImage)
.ExecuteNonQuery()
End With
MsgBox("บันทึกข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information, "แจ้งเตือน")
Call ShowProduct()
Call ClearTextboxProduct()
'Catch ex As Exception
' MsgBox("เกิดข้อผิดพลาดจากการบันทึกข้อมูล", MsgBoxStyle.Critical, "แจ้งเตือน")
' Exit Sub
'End Try
End Sub
ปุ่ม brows ครับ Code (VB.NET)
'button brows
Private Sub buttonBrows_Click(sender As Object, e As EventArgs) Handles buttonBrows.Click
Try
openImage = New OpenFileDialog
openImage.Filter = Nothing
If (openImage.ShowDialog() = Windows.Forms.DialogResult.OK) Then
getImage = openImage.FileName
ptImage.Image = Image.FromFile(getImage)
End If
Catch ex As Exception
Console.WriteLine("Error ButtonBrows")
Exit Sub
End Try
End Sub
ใครรูปวิธีช่วยบอกผมหน่อยนะครับ
Tag : .NET, VB.NET, VS 2005 (.NET 2.x), VS 2008 (.NET 3.x), VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)