PDA

View Full Version : Quick SQl server Question - Inserting New Columns(er, rows?)



musicisair
26 Feb 2008, 10:30 PM
My problem:
I'm updating a .net site and need to add two columns to an existing database. Here is the (abridged) code behind for the page I am working on:


using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Net.Mail;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class dev_signup : System.Web.UI.Page
{

SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["fire_biz"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
InsertMailForm();
}
}

private void InsertMailForm()
{
string[] newCntcts = new string[2];

newCntcts[0] = txtNme.Text;
newCntcts[1] = txtBizNme.Text;


SqlCommand dataCmd = new SqlCommand("InsertContcListng", objConn);
dataCmd.CommandType = CommandType.StoredProcedure;

dataCmd.Parameters.Add("@CntctNme", SqlDbType.VarChar).Value = newCntcts[0];
dataCmd.Parameters.Add("@CntctBizNme", SqlDbType.VarChar).Value = newCntcts[1];

objConn.Open();

int rows = dataCmd.ExecuteNonQuery();

dataCmd.Dispose();
objConn.Close();

return;
}
}


I know I need to edit string[] newCntcts like this:


string[] newCntcts = new string[4];
newCntcts[0] = txtNme.Text;
newCntcts[1] = txtBizNme.Text;

newCntcts[2] = newField1.Text;
newCntcts[3] = newField2.Text;


and eventually do this:


dataCmd.Parameters.Add("@CntctField1", SqlDbType.VarChar).Value = newCntcts[2];
dataCmd.Parameters.Add("@CntctField2", SqlDbType.VarChar).Value = newCntcts[3];


But I don't know how to create the columns CntctField1 and CntctField2.

Please help.