Using ExecuteScalar and SqlCommand Insert data into Database Table — ADO.Net , C Sharp — ASP.Net Example
ASP.Net Example-Using ExecuteScalar and SqlCommand Insert data into Database Table

Thursday, May 19, 2011

Using ExecuteScalar and SqlCommand Insert data into Database Table

using System;

using System.Data;

using System.Data.SqlClient;
   

public class InsertingDataUsingSQLStatementsExecuteScalar

{

static void Main(string[] args)

{
string CN="Data Source=(local); Initial Catalog = DBNAME; Integrated Security=true; 
SqlConnection objConnection = new SqlConnection(CN);
            

String Query ="INSERT INTO tblTest(ID, Contact, Email) VALUES(3, 'Bill', 'John')";

SqlCommand objCmd = new SqlCommand(Query, onConnection);objConnection.Open();
objCmd.ExecuteScalar();
objConnection.Close();

} 
}


No comments:

Post a Comment

ASPdotNET-Example