using System; using System.Data; using System.Data.SqlClient; class UsingParameterAndCommand { public static void Main() { string cn="server=localhost;database=DBTEST;uid=sa;pwd=sa"; SqlConnection Connection = new SqlConnection(cn); SqlCommand objCmd = Connection.CreateCommand(); objCmd.CommandText = "INSERT INTO ASPTable (" + " CustomerID, CompanyName, ContactName" + ") VALUES (" + " @CustomerID, @CompanyName, @ContactName" + ")"; objCmd.Parameters.Add("@CustomerID", "AB001"); objCmd.Parameters.Add("@CompanyName", "MicroSoft"); objCmd.Parameters.Add("@ContactName", "Bill"); Connection.Open(); objCmd.ExecuteNonQuery(); Console.WriteLine("Successfully added row to ASPTable "); Connection.Close(); } }
ASP.NET CSharpe ADO.NET and Sql Server and Javascript and jquery Example that is help to programmer
Thursday, May 19, 2011
using sql command with Parameters techniques insert data into database table
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment