V
Viktor Popov
Hi,
I'm trying to execute stored procedure and I collect its parameters from
WebForm. There is an error: Error converting data type varchar to int.
What could be the problem? Thanks! Here it is the code:
private void Button2_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=----;Initial
Catalog=---; User ID=---; Password=----");
SqlCommand cmd = new SqlCommand("prSVOFFRDATA", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@CITY", SqlDbType.VarChar,20));
cmd.Parameters["@CITY"].Value = DDL4.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@DISTR", SqlDbType.VarChar,20));
cmd.Parameters["@DISTR"].Value = DistrTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@PHONE", SqlDbType.Char,1));
if(PhoneCB.Checked)
{
cmd.Parameters["@PHONE"].Value = "Y";
}
else
{
cmd.Parameters["@PHONE"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@FURN", SqlDbType.Char,1));
if(FurnCB.Checked)
{
cmd.Parameters["@FURN"].Value = "Y";
}
else
{
cmd.Parameters["@FURN"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@HTR", SqlDbType.Char,1));
if(HtrCB.Checked)
{
cmd.Parameters["@HTR"].Value = "Y";
}
else
{
cmd.Parameters["@HTR"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@ESTTYPEID", SqlDbType.TinyInt));
cmd.Parameters["@ESTTYPEID"].Value = DDL2.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@TYPEOFFERID", SqlDbType.TinyInt));
cmd.Parameters["@TYPEOFFERID"].Value = DDL1.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@TYPECONSTRID", SqlDbType.TinyInt));
cmd.Parameters["@TYPECONSTRID"].Value = DDL3.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@USRNAM", SqlDbType.VarChar,20));
cmd.Parameters["@USRNAM"].Value = Session["usrName"].ToString();
cmd.Parameters.Add(new SqlParameter("@PRICE", SqlDbType.Int));
cmd.Parameters["@PRICE"].Value = PriceTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value = RoomsTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@SqMeters", SqlDbType.Int));
cmd.Parameters["@SqMeters"].Value = SQMetersTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@Floors", SqlDbType.Int));
cmd.Parameters["@Floors"].Value = FloorsTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@PIC", SqlDbType.VarChar,55));
cmd.Parameters["@PIC"].Value = PicTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@DESCR", SqlDbType.VarChar,255));
cmd.Parameters["@DESCR"].Value = DescrTB.Text.Trim();
cmd.Connection.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
I'm trying to execute stored procedure and I collect its parameters from
WebForm. There is an error: Error converting data type varchar to int.
What could be the problem? Thanks! Here it is the code:
private void Button2_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=----;Initial
Catalog=---; User ID=---; Password=----");
SqlCommand cmd = new SqlCommand("prSVOFFRDATA", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@CITY", SqlDbType.VarChar,20));
cmd.Parameters["@CITY"].Value = DDL4.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@DISTR", SqlDbType.VarChar,20));
cmd.Parameters["@DISTR"].Value = DistrTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@PHONE", SqlDbType.Char,1));
if(PhoneCB.Checked)
{
cmd.Parameters["@PHONE"].Value = "Y";
}
else
{
cmd.Parameters["@PHONE"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@FURN", SqlDbType.Char,1));
if(FurnCB.Checked)
{
cmd.Parameters["@FURN"].Value = "Y";
}
else
{
cmd.Parameters["@FURN"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@HTR", SqlDbType.Char,1));
if(HtrCB.Checked)
{
cmd.Parameters["@HTR"].Value = "Y";
}
else
{
cmd.Parameters["@HTR"].Value = "N";
}
cmd.Parameters.Add(new SqlParameter("@ESTTYPEID", SqlDbType.TinyInt));
cmd.Parameters["@ESTTYPEID"].Value = DDL2.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@TYPEOFFERID", SqlDbType.TinyInt));
cmd.Parameters["@TYPEOFFERID"].Value = DDL1.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@TYPECONSTRID", SqlDbType.TinyInt));
cmd.Parameters["@TYPECONSTRID"].Value = DDL3.SelectedItem.Value;
cmd.Parameters.Add(new SqlParameter("@USRNAM", SqlDbType.VarChar,20));
cmd.Parameters["@USRNAM"].Value = Session["usrName"].ToString();
cmd.Parameters.Add(new SqlParameter("@PRICE", SqlDbType.Int));
cmd.Parameters["@PRICE"].Value = PriceTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value = RoomsTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@SqMeters", SqlDbType.Int));
cmd.Parameters["@SqMeters"].Value = SQMetersTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@Floors", SqlDbType.Int));
cmd.Parameters["@Floors"].Value = FloorsTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@PIC", SqlDbType.VarChar,55));
cmd.Parameters["@PIC"].Value = PicTB.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@DESCR", SqlDbType.VarChar,255));
cmd.Parameters["@DESCR"].Value = DescrTB.Text.Trim();
cmd.Connection.Open();
cmd.ExecuteNonQuery();
conn.Close();
}