Sir,
I am new to asp.net i have installed visual studio community 2022 i want to know how to add 2 values and display the output, i need step procedure. please guide me
Sir,
I am new to asp.net i have installed visual studio community 2022 i want to know how to add 2 values and display the output, i need step procedure. please guide me
Hi @MohamedRafiN-6400,
The type of textBox1.Text is string and cannot be directly equal to int type.
If you use addition, you need to use the Convert.ToInt32 method to convert the specified value to a 32-bit signed integer.
If you have other questions, please click comment.
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hi @MohamedRafiN-6400,
What specific project do you want to use, asp.net webform?
Are you trying to add two values to the database?
You are a newbie, I suggest you to check Microsoft's related documentation, there are specific steps on it.
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Since you are starting new, I recommend you to go through ASP.Net Razor Pages along with Entity Framework Core to start building.
https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-6.0&tabs=visual-studio
The following link gives you a walkthrough for the CRUD operations (Create, Read, UPdate and Delete) .
https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/crud?view=aspnetcore-6.0
Hope this helps
what is the error in this code?
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FirstConsoleApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int input1 = Convert.ToInt32(textBox1.Text);
int input2 = Convert.ToInt32(textBox2.Text);
int result = input1 + input2;
MessageBox.Show("Addition result = " + result.ToString());
}
catch (Exception ex)
{
}
//int a, b, c;
// a = textBox1.Text;
// b = textBox2.Text;
// c = a + b;
//textBox5.Text = c;
}
}
}
Hi @MohamedRafiN-6400,
There is no problem with this code,
I suggest you create a WindowsFormsApp project to test this code.
If you have a new question, please open a new post.
Best regards,
Lan Huang
{
int a, b, c;
a = textBox1.Text;
b = textBox2.Text;
c = a + b;
textBox3.Text = c;
}
what is the error in this code sir?
i have converted into string to integer then also it is not working
int a, b, c;
Convert.ToInt32(this.textBox1.Text);
Convert.ToInt32(this.textBox2.Text);
a = textBox1.Text;
b = textBox2.Text;
c = a + b;
textBox3.Text = c;
The syntax is...
int a, b, c;
a = Convert.ToInt32(this.textBox1.Text);
b = Convert.ToInt32(this.textBox2.Text);
c = a + b;
textBox3.Text = c.ToString();
Reference documentation.
Convert.ToInt32 Method
I recommend int.TryParse().
7 people are following this question.