|
|
|
ถ้าเราเลือกวันที่ใน datetimepicker มันจะ error ค่ะ แต่ถ้าเราไม่เลือกวันที่ มันก็ให้บันทึกข้อมูลได้ ทำไงดีค่ะ |
|
|
|
|
|
|
|
ถ้าเราเลือกวันที่ใน datetimepicker มันจะ error ค่ะ แต่ถ้าเราไม่เลือกวันที่ มันก็ให้บันทึกข้อมูลได้ ทำไงดีค่ะ
Code (VB.NET)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
Dim a As String
Dim cmdtxt As String
a = ("รหัสสินค้า : " & txtserialno.Text & "") & vbNewLine
a &= ("ชื่อสินค้า : " & txtname.Text & "") & vbNewLine
a &= ("หน่วยสินค้า : " & cmbunit.Text & "") & vbNewLine
a &= ("ราคาขาย/หน่วย : " & txtsaleprice.Text & "") & vbNewLine
a &= ("ราคาทุน/หน่วย : " & txtbaseprice.Text & "") & vbNewLine
a &= ("จำนวนสินค้าถึงจุดสั่งซื้อ : " & txtbaypoint.Text & "") & vbNewLine
a &= ("คำแนะนำการใช้งาน : " & txtintroduction.Text & "") & vbNewLine
a &= ("สรรพคุณ : " & txtindication.Text & "") & vbNewLine
a &= ("คำเตือน : " & txtwarning.Text & "") & vbNewLine
a &= ("ปริมาณสินค้าคงคลัง : " & txttotalstock.Text & "") & vbNewLine
a &= ("ประเภทสินค้า : " & cmbtype.Text & "") & vbNewLine
a &= ("วันที่ผลิต : " & dtpmfd.Text & "") & vbNewLine
a &= ("วันหมดอายุ : " & dtpexp.Text & "")
MessageBox.Show(a, "แสดงผล", MessageBoxButtons.OK, MessageBoxIcon.Information)
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
If Adddata = 1 Then
cmdtxt = "insert into product (serialno,name,unit,saleprice,baseprice,baypoint,introduction,indication,warning,totalstock,type,mfd,exp) Values ('" & txtserialno.Text & "','" & txtname.Text & "','" & cmbunit.Text & "','" & txtsaleprice.Text & "','" & txtbaseprice.Text & "','" & txtbaypoint.Text & "','" & txtintroduction.Text & "','" & txtindication.Text & "','" & txtwarning.Text & "','" & txttotalstock.Text & "','" & cmbtype.SelectedIndex & "','" & dtpmfd.Value & "','" & dtpexp.Value & "')"
Else
cmdtxt = "update product set serialno = ('" & txtserialno.Text & "'),name = ('" & txtname.Text & "'),unit = ('" & cmbunit.Text & "'),saleprice = ('" & txtsaleprice.Text & "'),baseprice = ('" & txtbaseprice.Text & "'),baypoint = ('" & txtbaypoint.Text & "'),introduction = ('" & txtintroduction.Text & "'),indication = ('" & txtindication.Text & "'),warning = ('" & txtwarning.Text & "'),totalstock = ('" & txttotalstock.Text & "'),type = ('" & cmbtype.SelectedIndex & "'),mfd = ('" & dtpmfd.Value & "'),exp = ('" & dtpexp.Value & "') where serialno = '" & txtserialno.Text & "'"
End If
'MessageBox.Show("'" & txtid.Text & "','" & txtname.Text & "','" & txtaddress.Text & "', '" & txttel.Text & "','" & txtfax.Text & "','" & txtcomment.Text & "'", "ตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Question)
cmd.Connection = conn
cmd.CommandText = cmdTXT
cmd.ExecuteNonQuery()
conn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว ", "บันทึกข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnAdd.Enabled = True
btnSave.Enabled = False
btnDelete.Enabled = True
btnExit.Enabled = True
btnEdit.Enabled = True
txtserialno.Text = ""
txtname.Text = ""
cmbunit.Text = ""
txtsaleprice.Text = ""
txtbaseprice.Text = ""
txtbaypoint.Text = ""
txtintroduction.Text = ""
txtindication.Text = ""
txtwarning.Text = ""
txttotalstock.Text = ""
cmbtype.Text = ""
dtpmfd.Text = ""
dtpexp.Text = ""
txtserialno.Text = ""
txtname.Text = ""
cmbunit.Text = ""
txtsaleprice.Text = ""
txtbaseprice.Text = ""
txtbaypoint.Text = ""
txtintroduction.Text = ""
txtindication.Text = ""
txtwarning.Text = ""
txttotalstock.Text = ""
cmbtype.Text = ""
dtpmfd.Text = ""
dtpexp.Text = ""
txtserialno.Enabled = True
txtname.Enabled = True
cmbunit.Enabled = True
txtsaleprice.Enabled = True
txtbaseprice.Enabled = True
txtbaypoint.Enabled = True
txtintroduction.Enabled = True
txtindication.Enabled = True
txtwarning.Enabled = True
txttotalstock.Enabled = True
cmbtype.Enabled = True
dtpmfd.Enabled = True
dtpexp.Enabled = True
txtserialno.Focus()
End Sub
Tag : - - - -
|
|
|
|
|
|
Date :
2009-07-09 17:07:10 |
By :
ss |
View :
1460 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'" & dtpexp.Value & "'
เปลี่ยนเป็น
" & dtpexp.Value & "
|
|
|
|
|
Date :
2009-07-17 09:28:08 |
By :
saesee1125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ ขอบคุณค่ะ
|
|
|
|
|
Date :
2009-07-17 13:32:16 |
By :
ss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|