» »

[ASP.net] Master/detail - pretvorba VB v C#

[ASP.net] Master/detail - pretvorba VB v C#

SloDave ::

Vbistvu dost preprosto vprašanje, po tem članku skušam zadevo izdelat v C#. VB mi povzroča težave in nekako mi ni jasno kako bi tole pretvoru:

Kako naj definiram te dve funkciji da bo zraven šel result ds.Tables("tblDetails"), nekako vedno dobim error: 'System.Data.DataSet.Tables' denotes a 'property' where a 'method' was expected

Function GetDetails(ByVal x As String)
Dim conn As New SqlConnection("server=std04;uid=sa;pwd=;database=northwind")
Dim strSQL As String
Dim ds As New DataSet()

strSQL = "SELECT TOP 5 Customers.CompanyName, Products.ProductName, "
strSQL &= "convert(varchar, Orders.Orderdate, 101) as CDATE "
strSQL &= "FROM Employees INNER JOIN "
strSQL &= "Orders ON Employees.EmployeeID = Orders.EmployeeID INNER JOIN "
strSQL &= "Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN "
strSQL &= "[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN "
strSQL &= "Products ON [Order Details].ProductID = Products.ProductID "
strSQL &= "WHERE Employees.EmployeeID = " & x & " ORDER BY orderdate DESC"

Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "tblDetails")
Return ds.Tables("tblDetails")
End Function

kot tudi funkcija

Function GetAuthors() As DataTable
Dim ds As New DataSet()
Dim conn As New SqlConnection("server=std04;uid=sa;pwd=;database=northwind")
Dim strSQL As String
strSQL = "SELECT lastname, EmployeeID FROM Employees ORDER BY lastname"
Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "tblAuthors")
Return ds.Tables("tblAuthors")
End Function



Hvala

frudi ::

problem je v uporabi [] namesto () :)

poskusi tako:

private static DataTable GetDetails(string avstEmployeeId)
{
SqlConnection lConn;
String lstSql;
DataSet lDts;
SqlDataAdapter lAdapter;

lConn = new SqlConnection("server=.;uid=sa;pwd=banana;database=northwind");

lstSql = "SELECT TOP 5 Customers.CompanyName, Products.ProductName, ";
lstSql += "convert(varchar, Orders.Orderdate, 101) as CDATE ";
lstSql += "FROM Employees INNER JOIN ";
lstSql += "Orders ON Employees.EmployeeID = Orders.EmployeeID INNER JOIN ";
lstSql += "Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN ";
lstSql += "[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN ";
lstSql += "Products ON [Order Details].ProductID = Products.ProductID ";
lstSql += "WHERE Employees.EmployeeID = " + avstEmployeeId + " ORDER BY orderdate DESC";

lAdapter = new SqlDataAdapter(lstSql, lConn);

lDts = new DataSet();
lAdapter.Fill(lDts, "tblDetails");

return lDts.Tables["tblDetails"];
}

private static DataTable GetAuthors()
{
SqlConnection lConn;
String lstSql;
DataSet lDts;
SqlDataAdapter lAdapter;

lConn = new SqlConnection("server=.;uid=sa;pwd=banana;database=northwind");

lstSql = "SELECT lastname, EmployeeID FROM Employees ORDER BY lastname";

lAdapter = new SqlDataAdapter(lstSql, lConn);

lDts = new DataSet();
lAdapter.Fill(lDts, "tblDetails");

return lDts.Tables["tblDetails"];
}
1ACDoHVj3wn7N4EMpGVU4YGLR9HTfkNhTd... in case I've written something useful :)


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

C# težava

Oddelek: Programiranje
233721 (2567) mladec
»

[C#,SQL]

Oddelek: Programiranje
51241 (1154) JanOlMajti
»

Baza & c#

Oddelek: Programiranje
214156 (3214) xardas
»

[C#] Dostop do objekta iz različnih form

Oddelek: Programiranje
182163 (1876) Kekec
»

[C#] DATA GRID VIEW

Oddelek: Programiranje
131942 (1822) Kekec

Več podobnih tem