มันขึ้นerror ว่า Property access must assign to the property or use its value ค่ะจะต้องแก้ยังไง งง งง
ตัวอย่างโค้ด ที่จะต้องใช้เชื่อม database
Code (VB.NET)
Dim strConn As String
strConn = "Data Source=BLOG-8R3Q8PQKGG\SQLEXPRESS;Initial Catalog=VV;Integrated Security=True"
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
ShowData()
dgvequipmentList()
Dim strConn As String
strConn = "Data Source=BLOG-8R3Q8PQKGG\SQLEXPRESS;Initial Catalog=VV;Integrated Security=True"
Conn = New SqlConnection() ' เพิ่มเป็น Conn = New SqlConnection(strConn) ไม่โยน string เข้าจะเชื่อมได้ยังไงละครับ
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
ShowData()
dgvequipmentList()
Date :
2011-09-04 13:49:30
By :
SPIRITT
No. 7
Guest
ลองทำแล้วค่ะ มันยังผิดอนู่ในบรรทัดสุดท้าย
มันยังขึ้น Property access must assign to the property or use its value
********************************************************************************************* Code (VB.NET)
Option Explicit On
Option Strict On
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Public Class FormEquipment
Dim Conn As SqlConnection
Dim com As New SqlCommand()
Dim dr As SqlDataReader
Dim tr As SqlTransaction
Dim sb As New StringBuilder()
Private Sub ShowData()
sb.Remove(0, sb.Length)
sb.Append("SELECT ID,Name,Number")
sb.Append(" FROM Customer")
sb.Append(" ORDER BY CustomerID")
Dim sqlequipment As String = sb.ToString()
Dim dr As SqlDataReader
Dim dt As DataTable
com = New SqlCommand()
With com
.CommandType = CommandType.Text
.CommandText = sqlequipment
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
dgvequipmentList.DataSource = dt
Else
dgvequipmentList.DataSource = Nothing
End If
End With
dr.Close()
End Sub
Private Sub FormEquipment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
strConn = "Data Source=BLOG-8R3Q8PQKGG\SQLEXPRESS;Initial Catalog=VV;Integrated Security=True"
Conn = New SqlConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
ShowData()
dgvequipmentList() >>มันฟ้องว่าผิดตรงนี้ค่ะ<<
End Sub
Imports System.Data.SqlClient
Public Class Form2
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim connect As SqlConnection = New SqlConnection("Data Source=(local)\SQLEXPRESS;Initial Catalog=SaleOrder_0074;Integrated Security=True")
Dim StringSearch As String = txtSearch.Text
Dim SqlString As String = "Select*form Positions where PostID= '" + StringSearch + "' or PostName='" + StringSearch + "'"
Dim SqlCom As SqlCommand = New SqlCommand(SqlString, connect)
connect.Open()
Dim reader As SqlDataReader = SqlCom.ExecuteReader >>>>>> Error ตรงนี้อ่ะ Incorrect syntax near 'form'.
reader.Read()
If (reader.HasRows) Then
TextBox1.Text = reader("PostID").ToString
TextBox2.Text = reader("PostName").ToString
TextBox3.Text = reader("PostTel").ToString
TextBox4.Text = reader("PostDetial").ToString
reader.Close()
connect.Close()
End If
End Sub
End Class