C
CodingMann
Guest
I have a C# WinForms application, connecting to a SQL Server 2012 Express database.
I also have SQL Server Management Studio.
I pull data from 2-separate tables and insert them into a temporary table.
I then try to access the data in the temp table for usage in a report.
I can "See" the data in SSMS. However, I am unable to access the data via my application.
When I hover over the dataRow.ItemArray I see the desired data (5-columns of data), but have not been able to successfully assign them to my variables. Each time I iterate through the rows, no data is visible.
Below, I show one (of several) coding suggestions I found on line, but cannot extract any data.
BTW, the SQL Server forum thought this to be a .Net issue and not SQL.
Could someone suggest a practical way to actually extract the values from the ItemArray. Other suggestions online have proven unsuccessful. Also, they were showing how to ADD values to an ItemArray, whereas I need to extract values.
private void btnGetInfo_Click(object sender, EventArgs e)
{
string dateOUT = "";
string subject = "";
string person = "";
string location = "";
try
{
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\AppDB\Database.mdf;Database=MyDatabase;Integrated Security=True;Connection Timeout=30;User Instance=False"))
{
conn.Open();
SqlDataAdapter adap = new SqlDataAdapter();
SqlCommand cmdGetInfo = new SqlCommand(
"SELECT DateOUT, Subject, Person, Location, DateIN FROM ReportData WHERE DateIN IS NULL AND DateOUT IS NOT NULL ORDER BY DateIN DESC", conn);
adap.SelectCommand = cmdGetInfo;
DataTable dt = new DataTable();
adap.Fill(dt);
int rowCount = dt.Rows.Count;
int columnCount = dt.Columns.Count;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < columnCount; i++)
{
DataColumn dcol = dt.Columns;
for (int iRow = 0; iRow < rowCount; iRow++)
{
object cell = dt.Rows[iRow].ItemArray;
//How can I assign ItemArray’s values to above variables?
}
}
}
}
}
catch (SqlException ex) { MessageBox.Show(ex.Message); }
catch (System.Exception ex) { MessageBox.Show(ex.Message); }
}
Continue reading...
I also have SQL Server Management Studio.
I pull data from 2-separate tables and insert them into a temporary table.
I then try to access the data in the temp table for usage in a report.
I can "See" the data in SSMS. However, I am unable to access the data via my application.
When I hover over the dataRow.ItemArray I see the desired data (5-columns of data), but have not been able to successfully assign them to my variables. Each time I iterate through the rows, no data is visible.
Below, I show one (of several) coding suggestions I found on line, but cannot extract any data.
BTW, the SQL Server forum thought this to be a .Net issue and not SQL.
Could someone suggest a practical way to actually extract the values from the ItemArray. Other suggestions online have proven unsuccessful. Also, they were showing how to ADD values to an ItemArray, whereas I need to extract values.
private void btnGetInfo_Click(object sender, EventArgs e)
{
string dateOUT = "";
string subject = "";
string person = "";
string location = "";
try
{
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\AppDB\Database.mdf;Database=MyDatabase;Integrated Security=True;Connection Timeout=30;User Instance=False"))
{
conn.Open();
SqlDataAdapter adap = new SqlDataAdapter();
SqlCommand cmdGetInfo = new SqlCommand(
"SELECT DateOUT, Subject, Person, Location, DateIN FROM ReportData WHERE DateIN IS NULL AND DateOUT IS NOT NULL ORDER BY DateIN DESC", conn);
adap.SelectCommand = cmdGetInfo;
DataTable dt = new DataTable();
adap.Fill(dt);
int rowCount = dt.Rows.Count;
int columnCount = dt.Columns.Count;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < columnCount; i++)
{
DataColumn dcol = dt.Columns;
for (int iRow = 0; iRow < rowCount; iRow++)
{
object cell = dt.Rows[iRow].ItemArray;
//How can I assign ItemArray’s values to above variables?
}
}
}
}
}
catch (SqlException ex) { MessageBox.Show(ex.Message); }
catch (System.Exception ex) { MessageBox.Show(ex.Message); }
}
Continue reading...