コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            pytania q = new pytania();

            q.q_title     = textBox1.Text;
            q.q_opa       = textBox2.Text;
            q.q_opb       = textBox3.Text;
            q.q_opc       = textBox4.Text;
            q.q_opd       = textBox5.Text;
            q.q_opcorrect = textBox6.Text;
            q.q_addeddate = System.DateTime.Now.ToShortDateString();
            q.q_fk_ex     = comboBox1.SelectedValue.ToString();



            klasa_wchodzaca ic = new klasa_wchodzaca();

            string msg = ic.insert_srecord(q);

            MessageBox.Show(msg);
        }
コード例 #2
0
ファイル: klasa_wchodzaca.cs プロジェクト: roxol11/C_project
        public string insert_srecord(pytania q)
        {
            string        msg  = "";
            SqlConnection conn = new SqlConnection(connstring);

            try
            {
                SqlCommand cmd = new SqlCommand("[insert_questions]", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@q_title", SqlDbType.NVarChar).Value          = q.q_title;
                cmd.Parameters.Add("@q_opa", SqlDbType.NVarChar, 200).Value       = q.q_opa;
                cmd.Parameters.Add("@q_opb", SqlDbType.NVarChar, 200).Value       = q.q_opb;
                cmd.Parameters.Add("@q_opc", SqlDbType.NVarChar, 200).Value       = q.q_opc;
                cmd.Parameters.Add("@q_opd", SqlDbType.NVarChar, 200).Value       = q.q_opd;
                cmd.Parameters.Add("@q_opcorrect", SqlDbType.NVarChar, 200).Value = q.q_opcorrect;
                cmd.Parameters.Add("@q_addeddate", SqlDbType.NVarChar, 20).Value  = q.q_addeddate;
                cmd.Parameters.Add("@q_fk_ad", SqlDbType.Int).Value = q.q_fk_ad;
                cmd.Parameters.Add("@q_fk_ex", SqlDbType.Int).Value = q.q_fk_ex;

                conn.Open();
                cmd.ExecuteNonQuery();

                msg = "Baza załadowana!";
            }

            catch (Exception)
            {
                msg = "błąd ładowania bazy!";
            }

            finally
            {
                conn.Close();
            }

            return(msg);
        }