Embedded statement cannot be a declaration or labeled statement? [Resolved]

Posted by Sudheep.grandhe under C# on 12/1/2011 | Points: 10 | Views : 7133 | Status : [Member] | Replies : 3
Hi,

it shows the following error.How can i resolve this error.please do the needful.
Error:Embedded statement cannot be a declaration or labeled statement?

private void UpdateCustomerName_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
selectQueryString = "select * from tbl_customer";
conn.Open();
sqlDataAdapter = new SqlDataAdapter(selectQueryString, conn);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
dataTable = new DataTable();
int startrec=0;
if (txtstartrec .Text .Trim ()!="")
int StartRec = Convert.ToInt32(txtstartrec.Text);//it point outs the error here.
int MaxmiumRec = Convert.ToInt32(txtmaxrec.Text);
sqlDataAdapter.Fill(txtstartrec ,txtmaxrec ,dataTable );
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;
}

Best,
Sudheep.



Responses

Posted by: Sksingh on: 12/1/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

As of now you have only put the check for txtstartrec
Same way you have to write everywhere before converting to Int.
as below.
int StartRec= 0; 

int MaximumRec = 0;
if (txtstartrec .Text .Trim ()!="")
StartRec = Convert.ToInt32(txtstartrec.Text);
if (txtmaxrec.Text .Trim ()!="")
MaximumRec = Convert.ToInt32(txtmaxrec.Text);

try above code..



Regards,
Sunil

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

Posted by: Sksingh on: 12/1/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

if (txtstartrec .Text .Trim ()!="") 

int StartRec = Convert.ToInt32(txtstartrec.Text);//it point outs the error here.

If u see at above code then you are declared a variable inside if block.


int StartRec ;
if (txtstartrec .Text .Trim ()!="")
StartRec = Convert.ToInt32(txtstartrec.Text);//it point outs the error here.


hope it will work now..

Regards,
Sunil

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

Posted by: Sudheep.grandhe on: 12/1/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

It's again shows the same error.input string was not in a correct format.
int StartRec= 0;
if (txtstartrec .Text .Trim ()!="")
StartRec = Convert.ToInt32(txtstartrec.Text);
int MaximumRec = Convert.ToInt32(txtmaxrec.Text);//it shows the error here


Best,
Sudheep.

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

Login to post response