TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bruce Zelenka
NA
32
7.1k
records don’t print in my program but they print in viewer
Aug 14 2019 6:52 PM
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading;
using
System.Data.SqlClient;
namespace
BrucesConsoleApp {
class
Program {
static
void
Main(
string
[] args) {
try
{
// Create the connection object
SqlConnection connection =
new
SqlConnection();
connection.ConnectionString =
"Data Source=(localdb)\\MSSQLLocalDB;"
+
"Initial Catalog=Books;Integrated Security=True"
;
// Create the command object and set the connection,
// SELECT statement
SqlCommand selectCommand =
new
SqlCommand();
selectCommand.Connection = connection;
selectCommand.CommandText =
"SELECT * FROM Books"
;
selectCommand.CommandType = System.Data.CommandType.Text;
// Open the connection to the database
connection.Open();
SqlDataReader reader = selectCommand.ExecuteReader();
if
(reader.Read()) {
Console.WriteLine($
"{reader.GetString(1)} {reader.GetString(2)}"
);
Console.WriteLine($
""
);
}
reader.Close();
// Close the connection to the database
connection.Close();
}
catch
(Exception e) {
Console.WriteLine($
"Error"
);
Console.WriteLine(e.Message);
}
}
}
}
Reply
Answers (
3
)
How to generate parametrized insert statement for details wi
I am trying to populate a 3 column listView.