I am a learner of c#?

i am facing problem in learning it any body can share the links that helps me to learn c#.
at this moment i am trying this code but not working
cntname.Text = textname.Text;
int length = Textpwd.Text.Length;
cntpwd.Text = length;
i would like to get the length of the string and put it in a label with id cntpwd

Going to need a lot more detail. Is this a Windows form or web form? What are the ID names for the other fields? Are you trying to update the label via button click or keyup (as the user enters the data)?

on button click, it have to calculate the length of the string in the textpwd textbox and and have to be printed in the cntpwdlabel.

Is this a Windows form or web form?
What are the ID names for the other fields?

Can you copy/paste the code behind logic/code you have in full? (or at least the entire button click event)

this is the click event
protected void Button1_Click(object sender, EventArgs e)
{
cntname.Text = textname.Text;
int length = Textpwd.Text.Length;
cntpwd.Text = length.ToString();
}
and i also dont know what is this line means
protected void Button1_Click(object sender, EventArgs e)
caan you pleas explain this as well.

I guess you are developing ASP.NET application.Following code should work for you

Add in aspx TextBox controls with ids textpwd and cntpwdlabel.

Add in code behind
protected void Button1_Click(object sender, EventArgs e)
{
int length = textpwd.Text.Length;
cntpwdlabel.Text = length.ToString();
}

Please remember to use length.ToString(); as you can not assign numeric value to textbox.text

2 Likes

yeah i solved it, now i am looking for what this line means
protected void Button1_Click(object sender, EventArgs e)

yeah i solved it, now i am looking for what this line means
protected void Button1_Click(object sender, EventArgs e)
so…

This is event handler in C#.You link the controls in aspx to event handlers using attributes.If you see in aspx page you will see OnClick=“Button1_Click”.This will link OnClick event of the button to the Button1_Click event handler in C#.

1 Like

those are event handlers, thanks :slight_smile:

try {
SqlCommand cmd = new SqlCommand(ssql, conn);
cmd.ExecuteNonQuery();
conn.Close();
Label3.Text = “data inserted”;
}
catch (Exception ex)
{
Label3.Text = ex.Message;
}
what is the meaning of this one

This code executes sql command in the SQL Server database.ExecuteNonQuery() method executes the SQL Statement and the number records affected are returned.SQLConnection is used for connecting to SQL Server database.SQL Command is actually used to execute the command.Each SQL Command should have an associated SQL Connection object.

1 Like

This code executes sql command, ExecuteNonQuery method executes the SQL Statement. It is used to connecting the server data base.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.