Frm_Main.DataGridView2.DataSource = DirectCast(GetUser(Txt_Username.Text), DataTable)
Public Function GetUser(ByVal Name As String) As DataTable Dim query As String = "SELECT * FROM Users WHERE Username = @Name" Dim cnGetRecords As New OleDbConnection cnGetRecords.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Settings.EquipmentDatabase Dim cmdGetRecords As New OleDbCommand() Dim daGetRecords As New OleDbDataAdapter() Dim dsGetRecords As New DataTable() cmdGetRecords.Parameters.Clear() Try With cmdGetRecords .CommandText = query .CommandType = CommandType.Text .Parameters.AddWithValue("@Username", Name) .Connection = cnGetRecords End With DataAccess.HandleConnection(cnGetRecords) Dim oBindingSource As DataTable = DataAccess.GetDataTable(cmdGetRecords) 'now check to make sure a BindingSource was returned If Not oBindingSource Is Nothing Then 'return the binding source to the calling method Return oBindingSource Else 'no binding source was returned Throw New Exception("There was no BindingSource returned") Return Nothing End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Return Nothing Finally 'Close the connection DataAccess.HandleConnection(cnGetRecords) End Try End Function
On my main form I have the dataset called 'App_DataSet' with an empty table named 'Table_Users' , how would I fill the table instead of the datagridview?
Tried this and afew other things like it:
Frm_Main.App_DataSet.Tables.Item("Table_Users") = DirectCast(GetUser(Txt_Username.Text), DataTable)
but says 'Property item is read only'
Any help would be great thanks.