 |
|
บันทึกลงฐานข้อมูล sql ไม่ได้ ใช้ vb 2008 พอกดบันทึกแล้วเกิด Error ตามภาพจ้า |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Dim sqlADD As String 'เก็บคำสั่ง sql สำหรับเพิ่มข้อมูล
Dim cm As New SqlCommand
Dim conn As New SqlConnection
sqlADD = "INSERT INTO Empployee(empid,emppass,empidpro,empFname,empname,emplname,emphome,emptel)"
sqlADD &= "VALUES ('" & txtEm_id.Text & "','" & txtPass.Text & "','" & txtIdcard.Text & "','" & txtFname.Text & "','" & txtname.Text & "','" & txtLname.Text & "','" & txtAdd.Text & "','" & txtTel.Text & "')"
'ใช้ sqlcommand ในการเพิ่มข้อมูล
If MessageBox.Show("คุณต้องการเพิ่มรายชื่อใหม่ใช่หรือไม่?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
cm.CommandType = CommandType.Text
cm.CommandText = sqlADD
cm.Connection = conn
cm.ExecuteNonQuery()
MessageBox.Show("เพิ่มรายชื่อพนักงานแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtAdd.Clear()
End If

Tag : Ms SQL Server 2008, VB.NET, VS 2008 (.NET 3.x)
|
|
 |
 |
 |
 |
Date :
2012-04-28 18:36:55 |
By :
PhungBee |
View :
1466 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณยังไม่ Open Connection เลยครับ
Code (VB.NET)
Dim objConn As System.Data.SqlClient.SqlConnection
Dim objCmd As System.Data.SqlClient.SqlCommand
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(strConnString)
objConn.Open()
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
"VALUES ('C005','Weerachai Nukitram','[email protected]','TH',0,0)"
objCmd = New System.Data.SqlClient.SqlCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()
|
 |
 |
 |
 |
Date :
2012-04-28 20:54:30 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|