using System;
using System.Data.SqlClient;
namespace CSharpConnectToSQLServer
{
class Program
{
static void Main(string[] args)
{
dboFrank result = new dboFrank();
Console.WriteLine("Hello World!");
string connetionString = null;
SqlConnection cnn;
connetionString = @"Server = JOHN-PC\TEW_SQLEXPRESS; Database=myDB; Trusted_Connection=Yes;";
cnn = new SqlConnection(connetionString);
try
{
cnn.Open();
Console.WriteLine("Connection Open ! ");
SqlCommand command = new SqlCommand("SELECT PersonID, LastName, LargeNumber FROM dbo.Frank",cnn);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
result.LastName = reader["LastName"] as string;
Console.WriteLine("the last name is: " + result.LastName);
}
}
catch (Exception ex)
{
Console.WriteLine("Can not open connection ! " + ex.Message);
}
Console.ReadLine();
}
}
public class dboFrank
{
public int PersonID { get; set; }
public string LastName { get; set; }
public double LargeNumber { get; set; }
}
}
Wednesday, April 22, 2020
Reading from SQL server and assigning the value to a variable in a custom class.
Subscribe to:
Post Comments (Atom)
Creating a LAMP stack on AWS Free Tier
https://shawn-shi.medium.com/how-to-host-a-lamp-web-application-server-on-aws-ec2-for-free-8f6fc61463ed#:~:text=Its%20free%20tier%20allows...
-
In a regular annotation note, create a stack that looks the way you like. It will take a couple of trial and error attempts since there'...
-
Modifying profile of footing so that the notch shows up between the footing and the base of the foundation wall. https://youtu.be/0MPkykiWu0o
No comments:
Post a Comment