magritton
4/24/2014 - 2:07 PM

Simple Database insert in asp.net

Simple Database insert in asp.net

using System.Data;
using System.Data.SqlClient;

string strConnectionString = @"Password=FaY5FEC5;Persist Security Info=True;User ID=OPWDataWriter;
Initial Catalog=OPWBI;Data Source=opwsql03\sp2013tabular";

string strQuery = "";

strQuery = string.Format(@"INSERT  OPWCustomerService.OPWNewCustomer (ItemKey
                , DeniedPersonsNotes
                , DeniedPersonsCompleted
                , SpeciallyDesignatedNotes
                , SpeciallyDesignatedCompleted
                , DebarredPartyNotes
                , DebarredPartyCompleted
                , NonProliferationNotes
                , NonProliferationCompleted
                , CompanyAccept)
                VALUES ('{0}','{1}',{2},'{3}',{4},'{5}',{6},'{7}',{8},{9})",
                     txtItemKey.Text, txtDeniedPersons.Text, checkCheckBox(chkDeniedPersons),
                     txtSpeciallyDesignaated.Text, checkCheckBox(chkSpeciallyDesignaated), txtDebarredParty.Text,
                     checkCheckBox(chkDebarredParty), txtNonPiliforation.Text, checkCheckBox(chkNonPiliforation),
                     cboAcceptance.SelectedIndex
SqlConnection sc = new SqlConnection(strConnectionString);
sc.Open();

SqlCommand queryCommand = new SqlCommand(strQuery, sc);
int intSuccess = queryCommand.ExecuteNonQuery();