问题代码转换一个功能 [英] PROBLEM CODE CONVERSION ONE FUNCTION
本文介绍了问题代码转换一个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下午好,我正在vb.net 2015和sql 2014上申请我在c#中有这个代码我把它转换为vb .net但是它让我觉得有人可以帮我解决问题
good afternoon I'm making an application in vb.net 2015 and sql 2014 I have this code in c # I convert it to vb .net but it throws me problem someone could help me
原始代码
public ArrayList RetreiveSaleItems(int SaleID)
{
ArrayList ProductsList = new ArrayList();
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
SqlCommand command = new SqlCommand("SELECT ProductName, ProductPrice, ProductQuantity, ProductTotal FROM SaleItems where SaleID = '" + SaleID + "';", connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string ProductName = reader.GetString(0);
decimal ProductPrice = reader.GetDecimal(1);
int ProductQuantity = reader.GetInt32(2);
decimal ProductTotal = reader.GetDecimal(3);
ProductsList.Add(new Details() { Name = ProductName, Price = ProductPrice, Quantity = ProductQuantity, Total = ProductTotal });
}
}
reader.Close();
return ProductsList;
}
}
}
转换后的代码
Public Function RetreiveSaleItems(SaleID As Integer) As ArrayList
Dim ProductsList As New ArrayList()
Using connection As New SqlConnection(ConnectionString)
Dim command As New SqlCommand("SELECT ProductName, ProductPrice, ProductQuantity, ProductTotal FROM SaleItems where SaleID = '" & SaleID & "';", connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
Dim ProductName As String = reader.GetString(0)
Dim ProductPrice As Decimal = reader.GetDecimal(1)
Dim ProductQuantity As Integer = reader.GetInt32(2)
Dim ProductTotal As Decimal = reader.GetDecimal(3)
Function ProductsList.Add(Details( As New)
Name = ProductName, Price = ProductPrice, Quantity = ProductQuantity, Total = ProductTotal)
End Function
End While
End If
End Using
reader.Close()
Return ProductsList
End Function
推荐答案
ProductsList.Add(new Details with {.Name = ProductName, .Price = ProductPrice, .Quantity = ProductQuantity, .Total = ProductTotal})
这篇关于问题代码转换一个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文