[英]Dynamic Array to MS SQL Database
private void getRRvalue(string DELRRNO)
{
try {
DBSFCDataContext SFC = new DBSFCDataContext();
var query = (from i in SFC.POP10500s where i.POPRCTNM == DELRRNO select new { PONO = i.PONUMBER, DATEREC = i.DATERECD, VENDID = i.VENDORID, ITEMCODE = i.ITEMNMBR, QTYBAGS = i.QTYBAGS, QTYSHIP = i.QTYSHPPD, DEPT = i.TRXLOCTN });
foreach (var r in query)
{
string[] row = {
DELRRNO,
r.PONO,
Convert.ToDateTime(r.DATEREC).ToString(),
r.VENDID,
r.ITEMCODE,
r.QTYBAGS.ToString(),
r.QTYSHIP.ToString(),
r.DEPT
};
//glbVariables.getRRNO = ;
//glbVariables.getPONO = ;
//glbVariables.getRRdateRec = ;
//glbVariables.getVendID = ;
//glbVariables.getItemNO = ;
//glbVariables.getQtyBags = ;
//glbVariables.getQtyShipped = ;
//glbVariables.getLocnCode = ;
}
SFC.Connection.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()); }
}
I'm new to C#.NET and I was just thinking if I could use a dynamic array like for this code above do I need to declare a global array like this --> "public static string[] row;" 我是C#.NET的新手,我只是在想是否可以像上面的代码那样使用动态数组,是否需要像这样声明全局数组->“ public static string [] row;”。 so I can use this array string in another form by calling it with the data that I have stored from this function, could this happen in c#?
因此我可以通过使用我从该函数存储的数据调用它来以另一种形式使用此数组字符串,这会在c#中发生吗?
I need help here please anyone that is good at arrays in c#... 我在这里需要帮助,请擅长使用C#数组的人...
To get you desired results, you will have to do little more work. 为了获得理想的结果,您将需要做更多的工作。 I explain your solution using
List
. 我用
List
解释您的解决方案。
First create a class for your one query result: 首先为您的一个查询结果创建一个类:
public class OneRowData
{
public string DELRRNO;
public string PONO;
public string DATEREC;
public string VENDID;
public string ITEMCODE;
public string QTYBAGS;
public string QTYSHIP;
public string DEPT;
}
In your given code, create a List
of OneRowData
type and make it public static
to access it from outside the class as well: 在给定的代码中,创建一个
OneRowData
类型的List
,并使它成为public static
以从类外部也可以访问它:
public static List<OneRowData> QueryResults = new List<OneRowData>();
Now in your foreach
loop, create an object of OneRowData
, assing values to it and add it to the List
: 现在在您的
foreach
循环中,创建一个OneRowData
对象,将其OneRowData
,并将其添加到List
:
foreach (var r in query)
{
OneRowData Obj = new OneRowData();
//assing values to them
Obj.DATEREC = Convert.ToDateTime(r.DATEREC).ToString();
Obj.DELRRNO = DELRRNO;
Obj.DEPT = r.DEPT;
Obj.ITEMCODE = r.ITEMCODE;
Obj.PONO = r.PONO;
Obj.QTYBAGS = r.QTYBAGS.ToString();
Obj.QTYSHIP = r.QTYSHIP.ToString();
Obj.VENDID = r.VENDID;
//then add the object to your list
QueryResults.Add(Obj);
}
Now you can simply call your List
any where and fetch your data like this: 现在,您只需在任意位置调用
List
,然后按以下方式获取数据:
foreach (OneRowData Row in QueryResults)
{
//Row.DATEREC
//Row.DELRRNO
//call them like this and use as you need
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.