At the beginning...
First of all...
String SqlSelectRecords = ("select g.[Year] ,g.[EffectiveDate],g.[Volume] ,g.[Currency] ,g.[RateType] ,g.[MinimumRate] ,i.[State], i.[Location], i.[IndexEffective], i.[Page], i.[PageDescription] FROM[MultiYearWageGuide]as g join[MultiYearWageIndex] as i ON g.Volume= i.Volume AND g.Page = i.Page AND g.LocCode = i.Location WHERE store= " + int.Parse(textBox2.Text));
Such of query is
sql injection[
^] vulnerable!
Do not use concatenated strings! Use
parameterized queries[
^] instead!
Second of all...
String
is not the same as
string
! In a short:
Quote:
The string
type represents a sequence of zero or more Unicode characters. string
is an alias for System.String
in .NET.
FOr further details, please see:
String Class (System) | Microsoft Docs[
^]
string[
^]
As to your question...
I have no idea why do you want to use loop! Use
DataSet
,
DataAdapter
as Richard MacCutchan mentioned. You can use a
DataTable[
^] too.
Tip: use
using statement[
^] to easily manage disposable objects. For example:
dataGridView1.AutoGenerateColumns = true;
DataTable dt = new DataTable();
string sCs = "...";
string sCommand = "SELECT ... WHERE store = @aStore";
using (SqlConnection connection = new SqlConnection(sCs))
using(SqlCommand command = new SqlCommand(sCommand, connection))
{
connection.Open();
command.Parameters.AddWithValue("@aStore", textBox2.Text)
using(SqlDataReader reader = command.ExecuteReader())
dt.Load(reader);
}
dataGridView1.DataSource = dt;