 |
|
ขอถามหน่อยครับ ทำไมผมเชือมต่อ database ได้แล้ว แต่ทำไมผมดึง table ไม่ได้อ่าครับ |
|
 |
|
|
 |
 |
|
ลองแบบนี้ดูน่ะครับ
ผมเขียน C# ใช้ลักษณะนี้
ลองแก้ตรงนี้ดู
"select user,password From inputdata where user = '" & user.Text & "' and password = '" & password.Text & "'"
ให้เป็นแบบนี้ดูน่ะครับ
"select user,password From inputdata where user = ' " + user.Text + " ' and password = ' " + password.Text + " ' "
ลองดูน่ะครับถ้าไม่ได้ก้อรอผู้รู้มาตอบให้น่ะครับ
|
 |
 |
 |
 |
Date :
2014-06-30 01:35:17 |
By :
Zakariya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาใหม่อีกแล้วครับ มันขี้น fill selectcommand.connection property not been initialized อ่าๆๆ จะต้องทำยังไงหรอ

|
 |
 |
 |
 |
Date :
2014-06-30 10:14:30 |
By :
heloman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Dim Conn As SqlConnection
Dim Invalid As Integer
Dim rsToAffect As Long
Dim connetionString As String = "Data Source=PONGWICS2014-PC; Initial Catalog=data1;User ID=sa;Password=Pong"
Public sqlCommand As SqlCommand = New SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnn As SqlConnection
cnn = New SqlConnection(connetionString)
Dim strCon As String = cnn.ToString
Try
cnn.Open()
MsgBox("เชื่อมต่อได้แกล้ว ")
cnn.Close()
Catch ex As Exception
MsgBox("โอ้ๆ มันเกิดอะไรขึ้น ")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim aaa As String = ""
Dim bbb As String = ""
Try
Dim strSql As String = "select [user],[password] From inputdata where [user] = '" & user.Text & "' and [password] = '" & password.Text & "'"
Dim da As New SqlDataAdapter(strSql, connetionString)
Dim ds As New DataSet
Dim dt As New DataTable
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
Form2.Show()
Me.Hide()
Else
MessageBox.Show("ไม่พบผู้ใช้งาน หรือ รหัสผ่านไม่ถูกต้อง")
End If
Catch ex As Exception
MessageBox.Show("error TTT")
End Try
End Sub
End Class
หลีกเลี่ยง การตั้งชื่อ attribute ที่เป็น reserved word ใน database นะครับ
|
ประวัติการแก้ไข 2014-06-30 16:31:40
 |
 |
 |
 |
Date :
2014-06-30 16:28:51 |
By :
vbcrazy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|