Adding values of two text boxes in windows application

Posted by Chaithragm under C# on 4/3/2013 | Points: 10 | Views : 1362 | Status : [Member] | Replies : 3
Hi

Im having two textboxes
1)textbox1=value is binded from the database in the pageload
2)textbox2=users had to enter the value here

value from textbox2 is added to value in textbox1 and that value must save to server




Responses

Posted by: Jayasugan on: 4/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Chaithragm ,

Try This,

string Txt2=textbox2.text;
TextBox1.text=Txt2;

establish Sqlconnection
write SqlCommand="Update Table_Name set column_name='""+Txt2+'" where Yourcondition";

SAVED IN DB

In PageLoad
Asusual Bind Code for TextBox1


Mark as Answer if it is helpful to You

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

Posted by: Raj.Trivedi on: 4/3/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Chaithragm ,

Get the value of from the database in datatable

textbox1.text = dt.Rows[0]["Columnname"].to String

Textbox 2.text = "Your Value";

on Save button click button write this

string addvalues = textbox1.text + textbox2.text
and
save the string variable into database
as

insert into table Test(Testfield) values ('"+addvalues"');

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

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

Posted by: Satyapriyanayak on: 4/3/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Search_Edit
{
public partial class Form3 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
string str;
DataSet ds;

public Form3()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string v1 = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)).ToString();
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "insert into test values ('" + v1 + "')";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved");

}

private void Form3_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from test";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
textBox1.Text = (reader["sum"].ToString());

}
reader.Close();
con.Close();
}
}
}


If this post helps you mark it as answer
Thanks

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

Login to post response