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,027

HOME > .NET Framework > Forum > ช่วยหน่อยค่ะ มันไม่ให้เพิ่มข้อมูล เมื่อกดบันทึกมัน error ค่ะ



 

ช่วยหน่อยค่ะ มันไม่ให้เพิ่มข้อมูล เมื่อกดบันทึกมัน error ค่ะ

 



Topic : 028995

Guest




Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
Dim cmdtxt As String

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.Text & "','" & dtpmfd.Text & "','" & dtpexp.Text & "')"
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()
cmd.Connection = conn
Adddata = 1
cmd.CommandText = "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.Text & "','" & dtpmfd.Text & "','" & dtpexp.Text & "')"
'Dim strNewid As String
Dim sqlAllsupplier As String = " SELECT * FROM product Order By id desc "
'With cmd
' .CommandType = CommandType.Text
' .CommandText = sqlAllsupplier
' .Connection = conn
' strNewid = Format(Convert.ToInt32(.ExecuteScalar) + 1, "000")
' txtid.Text = strNewid
'End With
'Dim Reader As SqlDataReader
'Reader = cmd.ExecuteReader
'If Reader.Read Then
' 'MsgBox(Reader.Item(0))
' 'txtid.Text = Reader.Item("id")
'End If
conn.Close()
txtname.Focus()
btnAdd.Enabled = False
btnSave.Enabled = True
btnDelete.Enabled = False
btnExit.Enabled = True
btnEdit.Enabled = False

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()

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 cmdTXT As String
Dim a 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.Text & "','" & dtpmfd.Text & "','" & dtpexp.Text & "')"
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 & "'),cmbtype = ('" & cmbtype.Text & "'),dtpmed = ('" & dtpmfd.Text & "'),dtpexp= ('" & dtpexp.Text & "') 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



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-07-08 11:08:54 By : a View : 1172 Reply : 4
 

 

No. 1



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



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


ลองดูฟิวในฐานข้อมูลนะคับ






Date : 2009-07-08 14:18:29 By : jackky_jp
 


 

No. 2



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



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


ผมว่าส่ง Error มาให้ดูก่อนดีมั้ยครับ
มานั่งไล่ อย่างนี้มันยากนะครับ
Date : 2009-07-10 13:38:53 By : taobsd
 

 

No. 3



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



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


cmdTXT = " Insert Into product ( "
CmdTxt &= " serialno, name, unit, saleprice, baseprice, "
CmdTxt &= " baypoint, introduction, indication, warning, totalstock, "
CmdTxt &= " type, mfd, exp "
CmdTxt &= " ) Values ( "
CmdTxt &= " '" & txtserialno.Text & "', "
CmdTxt &= " '" & txtname.Text & "', "
CmdTxt &= " '" & cmbunit.Text & "', "
CmdTxt &= " '" & txtsaleprice.Text & "', "
CmdTxt &= " '" & txtbaseprice.Text & "', "

CmdTxt &= " '" & txtbaypoint.Text & "', "
CmdTxt &= " '" & txtintroduction.Text & "', "
CmdTxt &= " '" & txtindication.Text & "', "
CmdTxt &= " '" & txtwarning.Text & "', "
CmdTxt &= " '" & txttotalstock.Text & "', "

CmdTxt &= " '" & cmbtype.Text & "', "
CmdTxt &= " '" & dtpmfd.Text & "', "
CmdTxt &= " '" & dtpexp.Text & "' "
CmdTxt &= " )"
Else
cmdTXT = "update product set "
CmdTxt &= " serialno = '" & txtserialno.Text & "', "
CmdTxt &= " name = '" & txtname.Text & "', "
CmdTxt &= " unit = '" & cmbunit.Text & "', "
CmdTxt &= " saleprice = '" & txtsaleprice.Text & "', "
CmdTxt &= " baseprice = '" & txtbaseprice.Text & "', "
CmdTxt &= " baypoint = '" & txtbaypoint.Text & "', "
CmdTxt &= " introduction = '" & txtintroduction.Text & "', "
CmdTxt &= " indication = '" & txtindication.Text & "', "
CmdTxt &= " warning = '" & txtwarning.Text & "', "
CmdTxt &= " totalstock = '" & txttotalstock.Text & "', "
CmdTxt &= " cmbtype = '" & cmbtype.Text & "', "
CmdTxt &= " dtpmed = '" & dtpmfd.Text & "', "
CmdTxt &= " dtpexp= '" & dtpexp.Text & "' "
CmdTxt &= " where serialno = '" & txtserialno.Text & "'"
End If

ขอแนะนำหน่อยนะครับ

เวลาเราเขียนโค๊ดเนี่ย เรามากเขียนให้เห็นในหน้าเดียวในแต่ละบรรทัด แต่ลักษณะที่
คุณเขียนเนี่ยมันยาวทะลุหน้าจอเลยนะครับ มันทำให้เวลาไล่ Bug ทำได้ยาก
และอีกอย่าง คุณน่าจะเอา Error มาให้ดูด้วย เพื่อให้คนที่จะตอบให้เนี่ยเห็นปัญหาง่ายขึ้น
ขอแนะนำแค่เนี่ยแหละคับลองเอาไปปรับใช้ดูแล้วกันครับ เผื่อจะช่วยให้การแก้ Bug ง่ายขึ้น

แล้วที่แก้ให้เนี่ยก้อไม่มั่นใจนะคับว่าถูกไหม
Date : 2009-07-17 09:23:11 By : saesee1125
 


 

No. 4

Guest


ได้แล้วค่ะ ขอบคุณค่ะ
Date : 2009-07-17 13:33:38 By : a
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยค่ะ มันไม่ให้เพิ่มข้อมูล เมื่อกดบันทึกมัน error ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่