|
 |
|
สอบถาม error ของ vb ที่บอกว่า ไวยากรณ์ไม่ถูกต้องใกล้ Room_Number หาไม่เจอค่ะ |
|
 |
|
|
 |
 |
|
สอบถาม error ของ vb ที่บอกว่า ไวยากรณ์ไม่ถูกต้องใกล้ 'Room_Number หาไม่เจอค่ะ error " cm.ExecuteNonQuery()"
Code (VB.NET)
Private Sub BtnCusAdd_Click(sender As Object, e As EventArgs) Handles BtnCusAdd.Click
If lblNumber.Text = "" Then
MessageBox.Show("กรุณากดปุ่ม เพิ่มใหม่ หรือค้นหาข้อมูล")
Exit Sub
End If
sb = New StringBuilder
If SaveStatus = "add" Then
sb.Append("Insert Into Rooms(Room_Number,Room_Type,Room_Status,Room_Rent,Room_Size,Heater,Furniture,Cable,Wifi,Room_Photo)")
sb.Append("Values (@Room_Number,@Room_Type,@Room_Status,@Room_Rent,@Room_Size,@Heater,@Furniture,@Cable,@Wifi,@Room_Photo)")
Else
sb.Append("Update Rooms")
sb.Append(" Set Room_Status=@Room_Status,") '--เว้นวรรคหน้า Set
sb.Append("Room_Rent=@Room_Rent,")
sb.Append("Heater=@Heater,")
sb.Append("Furniture=@Furniture,")
sb.Append("Cable=@Cable,")
sb.Append("Wifi=@Wifi") '--ไม่ใส่คอมม่า
sb.Append(" Room_Number=@Room_Number") '--เว้นวรรคหน้า Where
End If
'--3.ส่งค่า
With cn
If .State = ConnectionState.Open Then .Close() '--ถ้าเปิด connection อยู่ให้ปิดไปก่อนเพื่อเปิดที่ไหนไว้มันจะ error
.ConnectionString = strConn
.Open()
End With
'Dim source As String = lblPic.Text
'Dim fName As String = lblNumber.Text
'Dim ext As String = source.Substring(source.LastIndexOf(".") + 1)
'lblPic.Text = "C:\PicRoom\" & fName & "." & ext
'Dim des As String = lblPic.Text
'File.Copy(source, des, True)
cm = New SqlCommand(sb.ToString, cn)
With cm.Parameters
.Add("@Room_Number", SqlDbType.NVarChar, 3).Value = lblNumber.Text
If cmtype.Text = "ห้องแอร์" Then
.Add("@Room_Type", SqlDbType.NVarChar, 1).Value = "A"
ElseIf cmtype.Text = "ห้องพัดลม" Then
.Add("@Room_Type", SqlDbType.NVarChar, 1).Value = "F"
Else
.Add("@Room_Type", SqlDbType.NVarChar, 1).Value = "B"
End If
If R5.Checked = True Then
.Add("@Room_Status", SqlDbType.NVarChar, 1).Value = "1"
ElseIf R6.Checked = True Then
.Add("@Room_Status", SqlDbType.NVarChar, 1).Value = "2"
Else
.Add("@Room_Status", SqlDbType.NVarChar, 1).Value = "3"
End If
.Add("@Room_Rent", SqlDbType.NVarChar, 7).Value = TbRent.Text
.Add("@Room_Size", SqlDbType.NVarChar, 10).Value = TbSize.Text
.Add("@Heater", SqlDbType.NVarChar, 1).Value = IIf(CheckBox1.Checked, "1", "0")
.Add("@Furniture", SqlDbType.NVarChar, 1).Value = IIf(CheckBox2.Checked, "1", "0")
.Add("@Cable", SqlDbType.NVarChar, 1).Value = IIf(CheckBox3.Checked, "1", "0")
.Add("@Wifi", SqlDbType.NVarChar, 1).Value = IIf(CheckBox4.Checked, "1", "0")
.Add("@Room_Photo", SqlDbType.NVarChar, 150).Value = lblPic.Text
End With
'--4.
cm.ExecuteNonQuery()
cn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว")
Cleardata()
lblNumber.Text = ""
lockdata(True, False)
ShowRoom()
End Sub
#End Region

Tag : .NET, Ms SQL Server 2008, VB.NET, VS 2012 (.NET 4.x)

|
|
 |
 |
 |
 |
Date :
2019-08-24 21:54:22 |
By :
2402438989802117 |
View :
1012 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sb.Append("Wifi=@Wifi") '--ไม่ใส่คอมม่า
sb.Append(" Room_Number=@Room_Number") '--เว้นวรรคหน้า Where
ไหน where อยู่ไหนครับ
sb.Append("Update Rooms")
sb.Append(" Set Room_Status=@Room_Status,") '--เว้นวรรคหน้า Set
อันนี้ เขาก็มี set เห็นไหมครับ
|
 |
 |
 |
 |
Date :
2019-08-25 06:51:22 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|