Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Deepak Baghel – Blogs

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Post
  • Categories
    • MS SQL
    • c#
    • CMD
    • WordPress
  • Groups page
  • Tags
C#

C#

Public group
70Views
0Users
1Post
Home/ Groups/C#
Pinned

Admin

September 24, 2024
using System;
using System.Data.SqlClient;

class Program
{
static void Main()
{
// Replace with your connection string
string connectionString = @"Data Source=.;Initial Catalog=BH_Report;Integrated Security=true;";

using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open(); // Open the connection
Console.WriteLine("Connection successful!");

// Example of executing a query
string query = "SELECT * FROM YourTable"; // Replace with your table name
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();

while (reader.Read())
{
Console.WriteLine(reader[0]); // Print the first column of each row
}

reader.Close();
}
catch (SqlException ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
} // Connection is automatically closed here
}
}

Explore

  • Post
  • Categories
    • MS SQL
    • c#
    • CMD
    • WordPress
  • Groups page
  • Tags

Footer

© 2024 Deepak Baghel All Rights Reserved.