這裏是場景:如何循環訪問數組並填充數據網格?
我有一個多行文本框,我正在閱讀每行到一個數組。然後我循環遍歷該數組,並在循環內逐個發送每個值到存儲的proc中,並獲取返回的狀態以判斷它是否有效。
問題是我相信我覆蓋了數據集變量,只填充了我檢索的最後一個值的數據網格。有沒有更好的方法來實現我想要做的事情?如果是這樣,請解釋。
protected void submitButton_Click(object sender, EventArgs e)
{
string textLines;
string[] textLine;
textLines = scannedCode.Text;
textLine = textLines.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
DataSet ds = null;
Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DataSet ds2 = null;
Database db2 = DatabaseFactory.CreateDatabase("ConnectionString");
foreach (string s in textLine)
{
try
{
DbCommand command2 = db.GetStoredProcCommand("sel_InfoByID_p");
db2.AddInParameter(command2, "@pGuid", DbType.String, s);
ds2 = db2.ExecuteDataSet(command2);
DataGrid1.DataSource = ds2;
DataBind();
}
catch (Exception ex)
{
}
}
}
這看起來就像[爲什麼我的數據網格只填充一行?](http://stackoverflow.com/questions/6668009/why-is-my-datagrid-only-populating-one-row)。你們兩個爲同一家公司工作?讀同一本書?參加同一班? :) – Tim
你和SkyDawg應該一起編碼。你有非常相似的編程風格。 http://stackoverflow.com/questions/6668009/why-is-my-datagrid-only-populating-one-row –
@Tim:打我吧。 :) –