How to connect .Net Application with Sql Server? part-2
https://www.youtube.com/watch?v=B9G2EFSfu8g
How to insert data in sql server using c# ?
static void Main(string[] args)
{
Console.Write("Enter First Name : ");
string fname = Console.ReadLine();
Console.Write("Enter Last Name : ");
string lname = Console.ReadLine();
Console.Write("Enter Age : ");
int age = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Salary : ");
int salary = Convert.ToInt32(Console.ReadLine());
string cs = "data source = .; database = TestDB; Integrated Security = true";
SqlConnection con = new SqlConnection(cs);
string query = string.Format("insert into Employee values('{0}','{1}',{2},{3})"
,fname,lname,age,salary);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int n = cmd.ExecuteNonQuery();
Console.WriteLine("{0} row(s) inserted successfully!...",n);
con.Close();
}
#informtechi
#ado.net
#sqlcommand
#c#
Download
0 formats
No download links available.
how to insert data in database using c# | sqlcommand in c# | Ado.net Tutorial by InfromTechi | NatokHD