Plz help me urgent Error 1 Cannot implicitly convert type 'short' to 'string'

Posted by Shail12345 under ASP.NET on 12/30/2013 | Points: 10 | Views : 1223 | Status : [Member] | Replies : 6
public partial class _Default : System.Web.UI.Page
{
BalCity bal = new BalCity();
DataTable dt = null;
string cid = null;
protected void Page_Load(object sender, EventArgs e)
{


if (!IsPostBack)
{

bindcity();
Bind();
}
}
void Bind()
{


if (Request.QueryString["id"]!=null)
{
cid = Convert.ToInt16(Request.QueryString["id"].ToString());

btnSubmit.Text = "Update";
bal.Action = "CityOnCondition";
bal.Id = cid;
//bal.City_Heading = cid;

dt=new DataTable();
dt=bal.BalBind();
txthead.Text = dt.Rows[0]["City_Heading"].ToString();
ddlcity.SelectedItem.Value = dt.Rows[0]["City_Name"].ToString();



}
}
private void bindcity()
{
bal.Action = "selectCity";
DataTable dt = bal.BalBind();
ddlcity.DataSource = dt;
ddlcity.DataTextField = "CityName";
ddlcity.DataValueField = "CityId";

ddlcity.Items.Insert(0, new ListItem("--Select--", "0"));
ddlcity.DataBind();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (btnSubmit.Text!="Update")
{
Save();
}
else
{
Update();
}

}

void Update()
{
bal.Action = "NewUpdateCondition";
bal.Id = cid;
bal.City_Name = ddlcity.SelectedItem.ToString();
bal.City_Heading = txthead.Text;
if (imgupload.HasFile)
{
imgupload.SaveAs(Server.MapPath("~/uploadimage/" + imgupload.FileName));
string image = "~/uploadimage/" + imgupload.FileName;
bal.City_Image = image;
}

int t = bal.BalOperation();
if (t > 0)
{

Response.Write("<script>alert('updated!!')</script>");

}
}
void Save()
{
if (imgupload.HasFile)
{

bal.Action = "insert_citynews";
bal.City_Name = ddlcity.SelectedItem.ToString();
bal.City_Heading = txthead.Text;
imgupload.SaveAs(Server.MapPath("~/uploadimage/" + imgupload.FileName));
string image = "~/uploadimage/" + imgupload.FileName;
bal.City_Image = image;

int t = bal.BalOperation();
if (t > 0)
{

Response.Write("<script>alert('Insertted!!')</script>");

}
}
else
{
Response.Write("<script>alert('Pleae select File')</script>");
}
}
}




Responses

Posted by: kgovindarao523-21772 on: 12/30/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Modify Convert.ToInt16() as Convert.ToString()

Thank you

Thank you,
Govind

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Instead of Convert.ToInt16() write Convert.ToInt32().

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shail12345 on: 12/30/2013 [Member] Starter | Points: 25

Up
0
Down
same problem not clear error

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi one side you have declared cid as string and converting string to int16,thats why you are getting error.


either convert to string as

cid = Convert.ToString(Request.QueryString["id"].ToString()); 


or declare variable cid as
int16 cid.


Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 12/31/2013 [Member] Starter | Points: 25

Up
0
Down
use parse.int

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/31/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
I have modified your code:-


public partial class _Default : System.Web.UI.Page
{
BalCity bal = new BalCity();
DataTable dt = null;
string cid = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{


if (!IsPostBack)
{

bindcity();
Bind();
}
}
void Bind()
{
if (Request.QueryString["id"] != null)
{
cid = Convert.ToString(Request.QueryString["id"].ToString());
btnSubmit.Text = "Update";
bal.Action = "CityOnCondition";
bal.Id = cid;
//bal.City_Heading = cid;
dt = new DataTable();
dt = bal.BalBind();
txthead.Text = dt.Rows[0]["City_Heading"].ToString();
ddlcity.SelectedItem.Value = dt.Rows[0]["City_Name"].ToString();
}
}

private void bindcity()
{
bal.Action = "selectCity";
DataTable dt = bal.BalBind();
ddlcity.DataSource = dt;
ddlcity.DataTextField = "CityName";
ddlcity.DataValueField = "CityId";

ddlcity.Items.Insert(0, new ListItem("--Select--", "0"));
ddlcity.DataBind();
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
if (btnSubmit.Text != "Update")
{
Save();
}
else
{
Update();
}
}

void Update()
{
bal.Action = "NewUpdateCondition";
bal.Id = cid;
bal.City_Name = ddlcity.SelectedItem.ToString();
bal.City_Heading = txthead.Text;
if (imgupload.HasFile)
{
imgupload.SaveAs(Server.MapPath("~/uploadimage/" + imgupload.FileName));
string image = "~/uploadimage/" + imgupload.FileName;
bal.City_Image = image;
}
int t = bal.BalOperation();
if (t > 0)
{
Response.Write("<script>alert('updated!!')</script>");
}
}

void Save()
{
if (imgupload.HasFile)
{
bal.Action = "insert_citynews";
bal.City_Name = ddlcity.SelectedItem.ToString();
bal.City_Heading = txthead.Text;
imgupload.SaveAs(Server.MapPath("~/uploadimage/" + imgupload.FileName));
string image = "~/uploadimage/" + imgupload.FileName;
bal.City_Image = image;
int t = bal.BalOperation();
if (t > 0)
{
Response.Write("<script>alert('Insertted!!')</script>");
}
}
else
{
Response.Write("<script>alert('Pleae select File')</script>");
}
}
}


Shail12345, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response