I have done a register form that register an account to a database, but to be available to use this on other computers I've decided to make a "settings form" there you can configure your SQL settings.

I want to take the values from the textBoxes in form2 and use it in form1.
something like this
Data Source='" + instanceName + "'; Initial Catalog='" + database + "'; User ID='" + User + "'; Password='" + Pass + "'; Integrated Security=TRUE");
Here is the code for Form1.
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.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textFirstName.Text == "settings")
{
Form2 form2 = new Form2();
form2.ShowDialog();
}
if (textFirstName.Text == "settings" == false)
{
SqlConnection myConnection = new SqlConnection("Data Source=Max-PC\\SQLExpress; Initial Catalog=Account; User ID=sa; Password=Windows; Integrated Security=TRUE");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("INSERT INTO tUser (sUserID, sUserPW, sUserName) VALUES ('" + textFirstName.Text + "','" + textLastName.Text + "','" + textFirstName.Text + "')", myConnection);
//da.InsertCommand.Parameters.Add("@FIRSTNAME", SqlDbType.VarChar).Value = textFirstName.Text;
//da.InsertCommand.Parameters.Add("@LASTNAME", SqlDbType.VarChar).Value = textLastName.Text;
myConnection.Open();
da.InsertCommand.ExecuteNonQuery();
myConnection.Close();
MessageBox.Show("Your account has been created!");
textFirstName.Text = "";
textLastName.Text = "";
}
}
}
}
Form2.
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;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
This post has been edited by Curtis Rutland: 02 October 2012 - 02:02 PM

New Topic/Question
Reply



MultiQuote





|