المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Placeholders with SQL statement



C# Programming
05-04-2010, 02:01 AM
If I have the following strings etc setup would I be able to use a placeholder?

I hope below makes sense, how would I let the placeholsers know what to reference?
string FirstName = txtFirstName.Text;
string MiddleName = txtMiddleName.Text;
string LastName = txtLastName.Text;
string idNumber = txtIdNumber.Text;
string eMailAddress = txtEmailAddress.Text;
string WebSite = txtWebsiteAddress.Text;
string HomePhone = txtHomePhone.Text;
string WorkPhone = txtWorkPhone.Text;
string FaxPhone = txtFaxPhone.Text;
string MobilePhone = txtMobilePhone.Text;
bool ContactVerified = chkVerified.Checked;
bool Tenant = chkTenant.Checked;
bool Owner = chkOwner.Checked;

SqlCommand myCommand = new SqlCommand("INSERT INTO contacts (first_name,middle_name,last_name,id_number,home_phone,work_phone,fax_phone,mobile_number,email_addr ess,website_address,contact_verified,tenant,owner)" +
"Values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')", myconnection);