how to get results from a select query and view them in VB.net in a form??
-
i think if the query is like sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY" in this the return type is a string and I could bind the output to a textbox and to a combobox. now if the query is like sCategory = "SELECT CATEGORY.* FROM CATEGORY" then how to view the results ?? I think Datagrid should be used....well not sure plz tell me how to bind and get the output in a datagrid .... and do tell me how to get a value from a particular cell to use it in another query. ==thnx waiting for a reply
-
i think if the query is like sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY" in this the return type is a string and I could bind the output to a textbox and to a combobox. now if the query is like sCategory = "SELECT CATEGORY.* FROM CATEGORY" then how to view the results ?? I think Datagrid should be used....well not sure plz tell me how to bind and get the output in a datagrid .... and do tell me how to get a value from a particular cell to use it in another query. ==thnx waiting for a reply
In this example I am using the datadapter, as you can bind the whole resultset to the grid in one command, with the datareader you have to loop through the resultset. Dim oConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection() Dim oCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand() Dim oDataTableResources As Data.DataTable = New Data.DataTable() Dim oDataTableSites As Data.DataTable = New Data.DataTable() Dim oDataAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter() Dim sSiteName As String Dim sResourceName As String Const iDayLength As Integer = 86400 sSQL = "Select * from Category" gsConnectString = " Initial Catalog=" & UCase(Trim(Me.txtDB.Text)) & _ ";Data Source=" & UCase(Trim(Me.txtSVR.Text)) & _ ";User ID=" & UCase(Trim(Me.txtUID.Text)) & _ ";Password=" & Trim(Me.txtPWD.Text) & ";" oConnection.ConnectionString = gsConnectString Try oConnection.Open() Catch o As System.Exception MsgBox(o.Message, MsgBoxStyle.Critical, gsMessageBoxHeader) Me.Cursor = Cursors.Default Exit Sub End Try Try oCommand.Connection = oConnection oCommand.CommandText = sSQL oDataAdapter.SelectCommand = oCommand 'fill the data adapter oDataAdapter.Fill(oDataTableResources) 'bind to the datagrid dbgrdDataGrid.DataSource = oDataTableResources dbgrdDataGrid.ParentRowsVisible = False Catch o As System.Exception MsgBox(o.Message) Me.Cursor = Cursors.Default End Try I do not have any code of getting a specific cell from the grid. I am sure you will be able to find samples on the web. YASP