question

MohamedRafiN-6400 avatar image
0 Votes"
MohamedRafiN-6400 asked ZhiLv-MSFT edited

New to Asp.Net Need connecting string and Add 2 values

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

dotnet-aspnet-generaldotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

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.
183579-1.jpg
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.


1.jpg (119.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sreejukg avatar image
0 Votes"
sreejukg answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MohamedRafiN-6400 avatar image
0 Votes"
MohamedRafiN-6400 answered LanHuang-MSFT commented

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;
     }
 }

}

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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.
183624-1.jpg
Best regards,
Lan Huang

0 Votes 0 ·
1.jpg (119.9 KiB)
MohamedRafiN-6400 avatar image
0 Votes"
MohamedRafiN-6400 answered Sowmitri commented

{
int a, b, c;
a = textBox1.Text;
b = textBox2.Text;
c = a + b;
textBox3.Text = c;
}

what is the error in this code sir?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
Logic seems no error

0 Votes 0 ·
MohamedRafiN-6400 avatar image
0 Votes"
MohamedRafiN-6400 answered

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;

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
0 Votes"
AgaveJoe answered

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().


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.