cast value of a textbox to a textbox in another form
Posted
by simon
on Stack Overflow
See other posts from Stack Overflow
or by simon
Published on 2010-04-29T05:57:03Z
Indexed on
2010/04/29
6:17 UTC
Read the original article
Hit count: 654
I'm trying to paste the values from a textbox in form1 to textbox in form2. I did that, but while i upgraded my aplication it stopped to work. I allso need that couse i get an error(incorect data type in conditional statement) when i want to insert a value from a textbox (to a access database) that's not on the form that makes the insert statemen. the code: string textFromForm1;
public Form2()
{
InitializeComponent();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
using (Form3 obrok = new Form3())
obrok.ShowDialog();
}
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
Form1 bmr=new Form1();
int masa;
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = bmr.masaTextBox.Text;
}
the code for insert statement: string conString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\Users\Simon\Desktop\save.mdb";
OleDbConnection empConnection = new OleDbConnection(conString);
string insertStatement = "INSERT INTO obroki_save "
+ "([ID_uporabnika],[ID_zivila],[skupaj_kalorij]) "
+ "VALUES (@ID_uporabnika,@ID_zivila,@skupaj_kalorij)";
OleDbCommand insertCommand = new OleDbCommand(insertStatement, empConnection);
insertCommand.Parameters.Add("@ID_uporabnika", OleDbType.Char).Value = users.iDTextBox.Text;
insertCommand.Parameters.Add("@ID_zivila", OleDbType.Char).Value = iDTextBox.Text;
insertCommand.Parameters.Add("@skupaj_kalorij", OleDbType.Char).Value = textBox1.Text;
empConnection.Open();
try
{
int count = insertCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
empConnection.Close();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
© Stack Overflow or respective owner