0
Answer

[resolved] - Passing a non viewed variable in a datatable

Ask a question


I have managed to read data into a datatable (see below) and can pass
the displaymember variable (description_id) back but I can not pass the other
variable in the table (prob_id) which is not displayed back to the server.

please look at my code below.  I know missing something I just can figure it
out.  I am assuming that it is in the subm_btn method but I can not get the
code right to pass the prob_id back.

Thanks
Mark

 

Table Example
prob_id  Description_id
-------- ---------------
1  oom
2  bad eggs
3  pirate kind


private void load_cb()
        {
            myconnection.Open();

            SqlCommand cmd = new SqlCommand("mp_statusopen", myconnection);
            cmd.CommandType = CommandType.StoredProcedure;
            DataTable dt_probdesc = new DataTable();
            SqlDataAdapter adaptor = new SqlDataAdapter(cmd);


            adaptor.Fill(dt_probdesc);

            Desc_cb.DataSource = dt_probdesc;
            Desc_cb.DisplayMember = "Description_id";    //"desc" is whatever the column in the server name is that you want displayed.
           
            myconnection.Close();

        }
       
        private void Form1_Load(object sender, EventArgs e)
        {
            load_cb();
        }

        private void Submit_btn_Click(object sender, EventArgs e)
        {
            myconnection.Open();

            SqlCommand Submit_btn = new SqlCommand("mp_submitbtn", myconnection);
            Submit_btn.CommandType = CommandType.StoredProcedure;


           
            Submit_btn.Parameters.AddWithValue("@Description", Desc_cb.Text);
            Submit_btn.Parameters.AddWithValue("@Prob_id", Desc_cb.SelectedValue);
            Submit_btn.Parameters.AddWithValue("@Call",Call_box.Text);
            Submit_btn.Parameters.AddWithValue("@date", DateTime.Now.ToString());

            Submit_btn.ExecuteNonQuery();
            myconnection.Close();
        }