 |
|
โค้ด insert ข้อมูล ช่วยตรวจสอบให้ด้วยนะครับ ขึ้น errer ว่า ExecuteNonQuery: CommandText property has not been initialized |
|
 |
|
|
 |
 |
|
Code (VB.NET)
myCommand.CommandText = CommandText
น่าจะลืมใส่ค่า SQL ให้มันครับ
|
 |
 |
 |
 |
Date :
2012-05-17 14:48:56 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดี๋ยวดูแป๊ปครับ
|
 |
 |
 |
 |
Date :
2012-05-17 15:31:22 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดทั้งหมดนะครับ
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class Form5
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MessageBox.Show("Exit Form Register?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Me.Close()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim CommandText As String = ""
If Me.txtName.Text = "" Then
MessageBox.Show("Please input (Name)")
Me.txtName.Focus()
Exit Sub
End If
If Me.txtPass.Text = "" Then
MessageBox.Show("Please input (Pass)")
Me.txtPass.Focus()
Exit Sub
End If
If Me.rdoOperater.Checked = False And Me.rdoTechnician.Checked = False Then
MessageBox.Show("Please input (Position)")
Exit Sub
End If
Dim myConnection As SqlConnection
myConnection = New SqlConnection("Server=saengtawan-pc\sql2008;UID=sa;PASSWORD=300881;Database=mydatabase;Max Pool Size=400;Connect Timeout=600;")
myConnection.Open()
Dim myCommand As SqlCommand = myConnection.CreateCommand()
CommandText = "INSERT INTO [mytable] ([Username], [Password], [Position])"
CommandText &= " VALUES ('" & Me.txtName.Text & "',"
CommandText &= "'" & Me.txtPass.Text & "',"
If Me.rdoOperater.Checked = True Then
CommandText &= "'Operator'"
ElseIf Me.rdoTechnician.Checked = True Then
CommandText &= "'Technician'"
End If
CommandText &= "')'"
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
MessageBox.Show("Save Successfully.")
Me.Hide()
Dim f As New Form3
f.Show()
End Sub
End Class
|
 |
 |
 |
 |
Date :
2012-05-17 15:34:03 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มตามที่ผมแนะนำยังครับ
Code (PHP)
Dim myCommand As SqlCommand = myConnection.CreateCommand()
CommandText = "INSERT INTO [mytable] ([Username], [Password], [Position])"
CommandText &= " VALUES ('" & Me.txtName.Text & "',"
CommandText &= "'" & Me.txtPass.Text & "',"
If Me.rdoOperater.Checked = True Then
CommandText &= "'Operator'"
ElseIf Me.rdoTechnician.Checked = True Then
CommandText &= "'Technician'"
End If
CommandText &= "')'"
myCommand.CommandText = CommandText.ToString()
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
|
 |
 |
 |
 |
Date :
2012-05-17 15:36:18 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-05-17 15:53:04 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Incorrect syntax near 'Technician')'. ขึ้น errer ตามนี้ครับ
|
 |
 |
 |
 |
Date :
2012-05-17 15:55:52 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
CommandText &= " )'"
เครื่องหมาย ' น่าจะเกินมา
|
 |
 |
 |
 |
Date :
2012-05-17 16:00:05 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2012-06-07 16:23:09 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|