Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulating TextBox based on ComBox, Insert into Database through TextBox
    primarykey
    data
    text
    <p>I'm having troubles populating TextBoxes based on a ComboBox, Also insertion code won't work.</p> <p>What should happen is, By selecting a customer from ComboBox, The details gets displayed on Text Boxes, And i can also add a customer to the ComboBox through the TextBoxes, Also there is a DataGridView displaying related info from another table based on my ComboBox selection but that's not the problem now.</p> <p>Note:</p> <p>I switched to Visual Studio 2012 recently, I'm assuming that's not a problem.</p> <p>ComboBox exception:</p> <blockquote> <p>An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll but was not handled in user code.</p> </blockquote> <p>Save button exception:</p> <blockquote> <p>Input string was not in a correct format.</p> </blockquote> <p>About the save button, The CustomerID is an Auto increment number, So i should be able to leave it's TextBox blank but it doesn't work when i do.</p> <p>Table Structure:</p> <pre><code>Customers CustomerID [int] [PK] [AutoNumber] Name [nvarchar] Phone1 [int] Phone2 [int] Address [nvarchar] Notes [ntext] </code></pre> <p>Code:</p> <pre><code>private void FillCombo() { string code = "SELECT CustomerID, Name FROM Customers"; SqlCeDataAdapter da = new SqlCeDataAdapter(code, clsMain.con); DataSet ds = new DataSet(); da.Fill(ds); cBox1.DataSource = ds.Tables[0]; cBox1.DisplayMember = "Name"; cBox1.ValueMember = "CustomerID"; } private void frmMain_Load(object sender, EventArgs e) { clsMain.con.Open(); FillCombo(); } private void cBox1_SelectedIndexChanged(object sender, EventArgs e) { string code = "SELECT * FROM Customers WHERE CustomerID='" + cBox1.Text + "'"; SqlCeDataAdapter da = new SqlCeDataAdapter(code, clsMain.con); SqlCeCommandBuilder cmd = new SqlCeCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); if (cBox1.SelectedIndex &gt; 0) { txt1.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString(); txt2.Text = ds.Tables[0].Rows[0]["Name"].ToString(); txt3.Text = ds.Tables[0].Rows[0]["Phone1"].ToString(); txt4.Text = ds.Tables[0].Rows[0]["Phone2"].ToString(); txt5.Text = ds.Tables[0].Rows[0]["Address"].ToString(); txt6.Text = ds.Tables[0].Rows[0]["Notes"].ToString(); } } private void stripSave_Click(object sender, EventArgs e) { string code = "INSERT INTO Customers VALUES (@CustomerID, @Name, @Phone1, @Phone2, @Address, @Notes)"; SqlCeCommand cmd = new SqlCeCommand(code, clsMain.con); cmd.Parameters.AddWithValue("@CustomerID", (txt1.Text); //Tried Parse and Convert. cmd.Parameters.AddWithValue("@Name", txt2.Text); cmd.Parameters.AddWithValue("@Phone1", txt3.Text); cmd.Parameters.AddWithValue("@Phone2", txt4.Text); cmd.Parameters.AddWithValue("@Address", txt5.Text); cmd.Parameters.AddWithValue("@Notes", txt6.Text); cmd.ExecuteNonQuery(); MessageBox.Show("Data stored."); } </code></pre> <p>Sorry if it's a long code, But i thought it would be easier to spot the problems this way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload