Hello Everybody
How can i return database that using SELECT
Here is my code
Public Function Recommened_GetUser(ByVal UserID As Integer, ByVal Path As String) As Data.DataTable
Dim dataset As New Data.DataSet
dataset.ReadXml(Path & filename)
Dim dt_ret As DataTable
Dim table As DataTable = dataset.Tables("Recommendhotel")
' Presuming the DataTable has a column named Date.
Dim expression As String
expression = "UserID='" & UserID & "'"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression)
Dim i As Integer
' Print column 0 of each returned row.
For i = 0 To foundRows.GetUpperBound(0)
dt_ret = foundRows(i)(0) // I want to return datatable
Next i
Return dt_ret
End Function
I want to select that only show depend on condition (UserID)
I really appreciate all the help you can give me!
Thanks in advance
Phuc Hoang
Loading
CrishPosted Dec 2, 2010, 1:39 AM
I had same problem.I think this code will help you.
public System.Data.DataTable GiveMeADataTable()
{
System.Data.SqlClient.SqlConnection conn = new
System.Data.SqlClient.SqlConnection("Server=YourServer;Initial
Catalog=pubs;Integrated Security=SSPI;");
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter adapter = new
System.Data.SqlClient.SqlDataAdapter();
adapter.SelectCommand = new
System.Data.SqlClient.SqlCommand("Select * From Authors", conn);
adapter.Fill(ds, "Authors");
return ds.Tables["Authors"];
}
Phuc HoangPosted Dec 1, 2010, 11:03 PM
Public Function Recommened_GetUser(ByVal UserID As Integer, ByVal Path As String) As Data.DataTable
Dim dataset As New Data.DataSet
dataset.ReadXml(Path & filename)
Dim table As DataTable = dataset.Tables("Recommendhotel")
' Presuming the DataTable has a column named .
Dim expression As String
expression = "UserID='" & UserID & "'"
Dim newDataTable As DataTable = table.Clone
Dim dataRows As DataRow() = table.Select(expression)
Dim typeDataRow As DataRow
For Each typeDataRow In dataRows
newDataTable.ImportRow(typeDataRow)
Next
Return newDataTable
End Function
Thanks for replying me
Suthish NairPosted Dec 1, 2010, 10:50 PM
Am not sure, replace below line and try..