|
|
|
รบกวนช่วยดูโค้ดให้ด้วยค่ะ คำสั่ง sql ที่เขียนมามันแสดงในdatagridviewทั้งหมดเลยค่ะ อยากให้มันแสดงเฉพาะ Bookseries,Book_name,Bowdate,Duedate ต้องเขียนคำสั่งยังไงค่ะ |
|
|
|
|
|
|
|
Code (VB.NET)
Private Sub TextBox8_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox8.KeyDown
If e.KeyCode = Keys.Enter Then
If TextBox8.Text.Trim() = "" Then Exit Sub
''sql = "SELECT dbo.Borrow.BorrowID, dbo.Borrow.MemberID, dbo.Borrow.M_Firstname, dbo.Borrow.M_Lastname, dbo.Borrow.Dateborrow, dbo.Borrow.Datereturn, "
''sql &= " dbo.Borrowdetail.BookID, dbo.Borrowdetail.B_name, dbo.Borrowdetail.st"
''sql &= " FROM dbo.Borrow INNER JOIN"
''sql &= " dbo.Borrowdetail ON dbo.Borrow.BorrowID = dbo.Borrowdetail.BorrowID"
''sql &= " WHERE (dbo.Borrowdetail.BookID = '" & TextBox8.Text & "') AND (dbo.Borrowdetail.st = 'ยืม')"
sql = "SELECT tb_Borrow.Borrow_ID, tb_Borrow.Mem_ID, tb_Borrow.Mem_name, tb_Borrow.Bowdate, tb_Borrow.Duedate, tb_Borrow.Status, "
sql &= " tb_detailborrow.BookCode, tb_detailborrow.Bookname, tb_detailborrow.Bookseries, tb_detailborrow.ReturnDate, tb_detailborrow.Borrowstatus"
sql &= " FROM tb_Borrow INNER JOIN"
sql &= " tb_detailborrow ON tb_Borrow.Borrow_ID = tb_detailborrow.Borrow_ID"
sql &= " WHERE (tb_Borrow.Mem_ID = '" & TextBox8.Text & "') AND (tb_detailborrow.Borrowstatus = 'ยืม')"
'sql &= " where BookID like '" & txtbookid.Text & "%' and stusbook1='อยู่บนชั้น'"
'sql = ""
'sql &= ""
da = New SqlDataAdapter(sql, conn) 'ประมาลผล
dtid = New DataTable
da.Fill(dtid)
If dtid.Rows.Count > 0 Then
DataGridView1.DataSource = dtid
TextBox8.Text = dtid.Rows(0).Item("Bookseries")
Label14.Text = dtid.Rows(0).Item("Borrow_ID")
TextBox1.Text = dtid.Rows(0).Item("Bookname")
DateTimePicker1.Text = dtid.Rows(0).Item("Bowdate")
DateTimePicker2.Text = dtid.Rows(0).Item("Duedate")
TextBox2.Text = dtid.Rows(0).Item("Mem_ID")
TextBox3.Text = dtid.Rows(0).Item("Mem_name")
'txtlast.Text = dtid.Rows(0).Item("M_Lastname")
'Me.showdata()
' Call showdata()
Dim num As Integer = 0
If CDate(DateTimePicker2.Text) < DateTimePicker3.Value Then
num = DateDiff(DateInterval.Day, CDate(DateTimePicker2.Text), DateTimePicker3.Value)
TextBox5.Text = num
Button1.Focus()
Else
TextBox5.Text = "0"
Button1.Focus()
End If
sql = " SELECT tb_member.Mem_ID, tb_Membertype.Membertype_ID, tb_Membertype.Membertype_name"
sql &= " FROM tb_member INNER JOIN "
sql &= " tb_Membertype ON tb_member.Membertype_ID = tb_Membertype.Membertype_ID"
sql &= " WHERE (tb_member.Membertype_ID = '" & TextBox2.Text & "') "
''sql = " SELECT dbo.Member.MemberID, dbo.Typemember.TypememberID, dbo.Typemember.Typemembername"
''sql &= " FROM dbo.Typemember INNER JOIN "
''sql &= " dbo.Member ON dbo.Typemember.TypememberID = dbo.Member.TypememberID"
''sql &= " WHERE (dbo.Member.MemberID = '" & TextBox2.Text & "') "
'sql &= " WHERE (dbo.Member.MemberID = '111') AND (dbo.Typemember.Typemembername = '111')"
'sql &= " WHERE (dbo.Borrow.MemberID = '" & txtmid.Text & "') AND (dbo.Borrowdetail.st = 'ยืม')"
'sql &= " where BookID like '" & txtbookid.Text & "%' and stusbook1='อยู่บนชั้น'"
'sql = ""
'sql &= ""
Dim str As String = ""
da = New SqlDataAdapter(sql, conn) 'ประมาลผล
Dim dtty As New DataTable
da.Fill(dtty)
If dtty.Rows.Count > 0 Then
str = dtty.Rows(0)(2)
'If str = "นักเรียน" Then
TextBox4.Text = "7"
If TextBox5.Text > "0" Then
TextBox7.Text = CInt(TextBox5.Text) * CInt(TextBox6.Text)
Else
TextBox7.Text = "0"
End If
'ElseIf str = "ครู อาจารย์" Then
' penalty.Text = "30"
' If TextBox10.Text > "0" Then
' TextBox7.Text = CInt(TextBox10.Text) * CInt(TextBox9.Text)
' Else
' TextBox7.Text = "0"
' End If
'End If
Else
End If
'End With
Else
DataGridView1.DataSource = Nothing
'MsgBox("Can't Borrow(หนังสือถูกยืมไปแล้ว)")
'txtbookid.Focus()
End If
End If
'Me.showdata()
End Sub
Tag : .NET, Ms SQL Server 2008, VS 2008 (.NET 3.x)
|
|
|
|
|
|
Date :
2011-08-21 23:46:20 |
By :
มะนาวหวาน |
View :
1067 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สามารถทำได้ที่ Query โดย Select เพาะ Column ที่ต้องการครับ หรือะเขียนสร้าง Column เองก็ได้ครับ
Code (VB.NET)
Private Sub PopulateData()
'*** BindData From Database **'
Dim objConn As OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydatabase.mdb"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Me.myDgv.DataSource = dt
'******************************'
Me.myDgv.Columns.Clear()
With myDgv.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(songsDataGridView.Font, FontStyle.Bold)
End With
Dim ColumnTextBox As DataGridViewTextBoxColumn
'*** Column (Select) ***'
Dim ColumnCheckBox As New DataGridViewCheckBoxColumn()
ColumnCheckBox.Width = 30
ColumnCheckBox.DataPropertyName = "Select"
Me.myDgv.Columns.Add(ColumnCheckBox)
'*** Checkbox in Header ***'
Dim ckBox As New CheckBox()
Dim rect As Rectangle = myDgv.GetCellDisplayRectangle(0, -1, True)
ckBox.Size = New Size(18, 18)
rect.X = rect.Location.X + (rect.Width / 4)
ckBox.Location = rect.Location
AddHandler ckBox.CheckedChanged, New EventHandler(AddressOf ckBox_CheckedChanged)
Me.myDgv.Controls.Add(ckBox)
myDgv.Columns(0).Frozen = False
'*** Column (CustomerID) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "CustomerID"
ColumnTextBox.HeaderText = "CustomerID"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
'*** Column (Name) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Name"
ColumnTextBox.HeaderText = "Name"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
'*** Column (Email) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Email"
ColumnTextBox.HeaderText = "Email"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
'*** Column (CountryCode) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "CountryCode"
ColumnTextBox.HeaderText = "CountryCode"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
'*** Column (Budget) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Budget"
ColumnTextBox.HeaderText = "Budget"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
'*** Column (Used) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "Used"
ColumnTextBox.HeaderText = "Used"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.myDgv.Columns.Add(ColumnTextBox)
End Sub
|
|
|
|
|
Date :
2011-08-22 06:21:54 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|