 |
|
รบกวนช่วยบอกวิธีในการใช้ CheckBox เรียกฐานข้อมูลจาก SQLserver ของvbให้ที |
|
 |
|
|
 |
 |
|
รบกวนช่วยบอกวิธีในการใช้ CheckBox เรียกฐานข้อมูลจาก SQLserver ของvbให้ที
จุดประสงค์คือต้องการให้ CheckBox1+2+3 = True แล้วแสดง
strSQL = "SELECT name,subname,address,phone,Office FROM history"
ออกมาที่ DataGridView ที่ชื่อ dgvSQL รบกวนช่วยที
นี้เป็นCodeที่เขียนอยู่
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Public Class FrmCheckBox_SQL
Dim conn As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet()
Private Sub BtnExecSQL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExecSQL.Click
Dim strconn As String = ""
strconn = "Data Source=SGH120QXPK-HP;Initial Catalog=dbTEST2;Integrated Security=True"
If conn.State = ConnectionState.Open Then
conn.Close()
Else
conn.ConnectionString = strconn
conn.Close()
End If
Try
Dim strSQL As String = ""
If CheckBox1.Checked = True Then
strSQL = "SELECT name,subname FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
ElseIf CheckBox2.Checked = True Then
strSQL = "SELECT address,phone FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
ElseIf CheckBox3.Checked = True Then
strSQL = "SELECT Office FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
End If
da = New SqlDataAdapter(strSQL, conn)
ds.Tables.Clear()
da.Fill(ds, "history")
dgvSQL.DataSource = ds.Tables("history")
TxtResult.Text = "สำเร็จ : มีข้อมูลทั้งหมด" & ds.Tables("history").Rows.Count.ToString & "แถว"
Catch ex As Exception
MessageBox.Show("กรุณาเลือกคำสั่ง", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Tag : .NET, VBScript, VB.NET
|
|
 |
 |
 |
 |
Date :
2012-07-11 14:08:13 |
By :
KT-Revenue |
View :
1421 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
c# นะค่ะ
if (checkBox1.Checked == true & checkBox2.Checked == true & checkBox3.Checked == true)
{
เข้าเงื่อนไข
strSQL = "SELECT name,subname,address,phone,Office FROM history"
}
else
{
}
|
 |
 |
 |
 |
Date :
2012-07-11 14:55:23 |
By :
meneger |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มอีกเงื่อนไขนึงสิ
If c1.Checked And c2.Checked And c3.Checked Then
|
 |
 |
 |
 |
Date :
2012-07-11 15:07:53 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับแล้วจะลองดู
|
 |
 |
 |
 |
Date :
2012-07-12 08:49:26 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทั้ง2วิธีแล้วไม่ได้เลยครับ
|
 |
 |
 |
 |
Date :
2012-07-12 11:11:11 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะมีวิธีที่ทำให้ CheckBox1+2+3 = True แล้วนำ strSQL ของแต่ละ CheckBox มาแสดงต่อๆกันนะครับ มีไหมครับ
|
 |
 |
 |
 |
Date :
2012-07-12 11:16:33 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim strSQL As String = String.Empty
If CheckBox1.Checked And CheckBox2.Checked And CheckBox3.Checked Then
strSQL = "SELECT name,subname,address,phone,Office FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
End If
If CheckBox1.Checked = True Then
strSQL = "SELECT name,subname FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
ElseIf CheckBox2.Checked = True Then
strSQL = "SELECT address,phone FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
ElseIf CheckBox3.Checked = True Then
strSQL = "SELECT Office FROM history"
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
End If
|
 |
 |
 |
 |
Date :
2012-07-12 11:19:43 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับที่ช่วยแนะนำ แต่ก็ยังไม่ได้อยู่ดีครับ
|
 |
 |
 |
 |
Date :
2012-07-12 13:16:50 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รันได้แล้วครับ ผมลองใช้วิธีนี้ดู
โดยสร้าง CheckBox123 แล้วให้ Visible = False
Code (VB.NET)
Private Sub BtnExecSQL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExecSQL.Click
Dim strconn As String = ""
strconn = "Data Source=SGH120QXPK-HP;Initial Catalog=dbTEST2;Integrated Security=True"
If conn.State = ConnectionState.Open Then
conn.Close()
Else
conn.ConnectionString = strconn
conn.Close()
End If
Try
Dim strSQL As String = ""
If CheckBox1.Checked And CheckBox2.Checked And CheckBox3.Checked Then
CheckBox123.Checked = True
End If
If CheckBox123.Checked = True Then
strSQL = "SELECT realname,subname,address,phone,Office FROM history"
ElseIf CheckBox1.Checked = True Then
strSQL = "SELECT realname,subname FROM history"
ElseIf CheckBox2.Checked = True Then
strSQL = "SELECT address,phone FROM history"
ElseIf CheckBox3.Checked = True Then
strSQL = "SELECT Office FROM history"
End If
dgvSQL.ColumnHeadersVisible = True
dgvSQL.RowHeadersVisible = True
da = New SqlDataAdapter(strSQL, conn)
ds.Tables.Clear()
da.Fill(ds, "history")
dgvSQL.DataSource = ds.Tables("history")
TxtResult.Text = "สำเร็จ : มีข้อมูลทั้งหมด" & ds.Tables("history").Rows.Count.ToString & "แถว"
Catch ex As Exception
MessageBox.Show("กรุณาเลือกคำสั่ง", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
ขอบคุณมากๆครับ ถ้าไม่ได้แนวทางจากพวกคุณ ผมคงยังคิดไม่ออก ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-07-12 13:25:46 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|