PDA

View Full Version : نحوه نمایش اطلاعات در GridView



mahmood_hedesh
چهارشنبه 15 شهریور 1391, 16:06 عصر
من یه سری اطلاعات از دیتابیس می گیرم و می خواهم آن را در GridView نمایش بدهم.
برنامه من این طوری که به وسیله GridView تمامی محصولات را نشان داده میشود. حالا می خواهم به وسیله دکمه Sort محصولاتی را که فقط وضعیت آن ها مثلا تعمیری هستند را در GridView نشان دهم. و به قولی حالتی فیلتری به وسیله Sort به وجود آورم.

حالا نمی دانم چطوری این محصولات مثلا تعمیری را در GridView نمایش بدهم؟

Reza Safa
چهارشنبه 15 شهریور 1391, 17:54 عصر
این sort نیست این search است
برای اینکه موارد دلخواه خود را در grid view نمایش دهید نیاز به این هست که چطور query می نویسید
query نوشتن هم که ساده است فقط کافی بلد باشی
بعد آنها را توسط ado ست می کنی و gridview را به dataset وصل می کنی
.....



Public ComBuild As New SqlCommandBuilder 'Build Command For Database
Public Con As New SqlConnection 'Connection to Database
Public Com As New SqlCommand 'Command For Database
Public dAdapter As New SqlDataAdapter 'Data Adapter
Public dReader As SqlDataReader 'Serach & Read From Database
Public dSet As New DataSet 'Data Set


Public Sub DisplaySqlErrorCollection(ByVal myException As SqlException)
Dim i As Integer
For i = 0 To myException.Errors.Count - 1
MessageBox.Show("Index #" + i.ToString() + ControlChars.Cr _
+ "Message: " + myException.Errors(i).Message + ControlChars.Cr _
+ "Source: " + myException.Errors(i).Source + ControlChars.Cr , "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Next i
End Sub
Public Sub Connection(ByVal constring As String)
Con.Close()
'----
Try
Con.ConnectionString = constring
Con.Open()
Catch ex As Exception
MessageBox.Show(ex.Source + vbCrLf + ex.Message)
Application.Exit()
End Try
End Sub
Public Sub Command(ByVal sqlCommand As String, ByVal TableName As String)
Try
'stop_out_box()

Connection(pdp)
dSet.Clear()
'----
Com.Connection = Con
Com.CommandText = sqlCommand
'----
dAdapter.SelectCommand = Com

dAdapter.Fill(dSet, TableName)
'Start_out_box()
Catch ex As Exception
'Start_out_box()

MessageBox.Show(ex.Source + vbCrLf + ex.Message)
End Try
End Sub
Public Sub ExecuteCommand(ByVal sqlCommand As String, ByVal TableName As String)
Try
'stop_out_box()

dSet.Clear()
'----
Connection(pdp)


Com.Connection = Con
Com.CommandText = sqlCommand

Com.ExecuteReader()

Con.Close()
'Start_out_box()
Catch ex As Exception
'Start_out_box()
Con.Close()
MessageBox.Show(ex.Source + vbCrLf + ex.Message)
End Try
frmShowInfoLoans.Fill_Main_Information()
End Sub
Public Function Get_ExecuteCommand(ByVal sqlCommand As String, ByVal TableName As String) As String
Try
'stop_out_box()

dSet.Clear()
'----
Connection(pdp)


Com.Connection = Con
Com.CommandText = sqlCommand

Dim strVal As String = ""

If Com.ExecuteScalar Is DBNull.Value Then
strVal = "0"
Else
strVal = Com.ExecuteScalar
End If
'Start_out_box()
Con.Close()
Return strVal
Catch ex As Exception
'Start_out_box()
Con.Close()
MessageBox.Show(ex.Source + vbCrLf + ex.Message)
End Try

End Function





برای نمایش در gridview



Dim SQLSelect As String = "SELECT * FROM tblname where m = 'تعمیرات'
dll.Command(SQLSelect, "tblname")
With DGV
.DataSource = dll.dSet
.DataMember = "tblname"

End With
'----
dll.Con.Close()

mahmood_hedesh
چهارشنبه 15 شهریور 1391, 18:25 عصر
یادم من پایگاه هم access هست به خاطر همین از ADo نمیشه استفاده کرد ، اگر درست می گم با اکسس چه کنم؟