На самом деле ваша проблема заключалась в том, что вы связываете сетку на КАЖДОЙ итерации, иначе ничего плохого в коде. Так что вместо:
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)
{
}
}
сделать это:
foreach (string s in textLine)
{
try
{
DbCommand command2 = db.GetStoredProcCommand("sel_InfoByID_p");
db2.AddInParameter(command2, "@pGuid", DbType.String, s);
ds2 = db2.ExecuteDataSet(command2);
}
catch (Exception ex)
{
}
}
DataGrid1.DataSource = ds2;
DataBind();
Однако, поскольку вы выполняете циклы с той же функциональностью, для оптимизации я предлагаю:
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand("MyStoredProcName", connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter submitParam = new SqlParameter("@pGuid", SqlDbType.String);
//use SqlDbType.Bit if you are returning true/false.
SqlParameter returParameter = new SqlParameter("@ReturnedParam", SqlDbType.String);
returParameter.Direction = ParameterDirection.Output;
connection.Open();
foreach (string s in textLine)
{
returnString.Value = s;
command.Parameters.Clear();
command.Parameters.Add(submitParam);
command.Parameters.Add(returParameter);
try
{
command.ExecuteNonQuery();
store the returned string in DataTable, BindingList<string> or any, but this is how to retrieve it:
Convert.ToString(Command.Parameters["@ReturnedParam"].Value, CultureInfo.CurrentCulture)
}
catch (Exception ex)
{
;;
}
}
connection.Close();
Do the grid binding here