J
J Vallee
Guest
I have a SQLEXPRESS v15 table (called prmtcnfg) in a database called PLV. I am using VS 2019 and C#.
The table has one row in it.
I can connect to the server and it shows the table (and fields) in the Server Explorer Windows
This is what I have so far... but the reader = command.ExecuteReader(); doesn't return the row.
What am I missing?
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=WIN10\SQLEXPRESS;";
conn.ConnectionString = conn.ConnectionString + "Initial Catalog=PLV;";
conn.ConnectionString = conn.ConnectionString + "User id=PLV;";
conn.ConnectionString = conn.ConnectionString + "Password=PLV;";
conn.Open();
MessageBox.Show("connection open"); // connects just fine
// now go look for record
SqlCommand command;
SqlDataReader reader;
// select all columns in the row
string sql;
sql = "Select Top 1 * from prmtcnfg";
// this doesn't work either
//sql = "Select * from prmtcnfg";
command = new SqlCommand(sql, conn);
reader = command.ExecuteReader();
// READER.HASROWS shows FALSE -- WHY??
{
if (reader.HasRows)
{
app.serinumb = Convert.ToString(reader["SeriNumb"]);
MessageBox.Show(app.serinumb);
}
else
{
MessageBox.Show("no rows - has rows is false");
}
}
Continue reading...
The table has one row in it.
I can connect to the server and it shows the table (and fields) in the Server Explorer Windows
This is what I have so far... but the reader = command.ExecuteReader(); doesn't return the row.
What am I missing?
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=WIN10\SQLEXPRESS;";
conn.ConnectionString = conn.ConnectionString + "Initial Catalog=PLV;";
conn.ConnectionString = conn.ConnectionString + "User id=PLV;";
conn.ConnectionString = conn.ConnectionString + "Password=PLV;";
conn.Open();
MessageBox.Show("connection open"); // connects just fine
// now go look for record
SqlCommand command;
SqlDataReader reader;
// select all columns in the row
string sql;
sql = "Select Top 1 * from prmtcnfg";
// this doesn't work either
//sql = "Select * from prmtcnfg";
command = new SqlCommand(sql, conn);
reader = command.ExecuteReader();
// READER.HASROWS shows FALSE -- WHY??
{
if (reader.HasRows)
{
app.serinumb = Convert.ToString(reader["SeriNumb"]);
MessageBox.Show(app.serinumb);
}
else
{
MessageBox.Show("no rows - has rows is false");
}
}
Continue reading...