cathiec Posted March 10, 2004 Posted March 10, 2004 i have a form on which the primary key is the employee number. the user is required to enter training needs, time scale and cost for each employee number. the problem is that there can be more than one entry for trainings needs cost and time scale. i ahve designed the form so that there are 8 times the information can be added. my problem comes when i try to insert as i am setting the parameters for the stored procedure equal to specici text boxs and drop down lists instead of the 8. here is my code private void Button1_Click(object sender, System.EventArgs e) { //SqlConnection conn = new SqlConnection("data source=NT20'\'SQL02;initial catalog=webholidays;integrated security=SSPI;persist security info=False;workstation id=PC2677;packet size=4096"); SqlDataAdapter da; DataSet ds; SqlParameter workParam; da = new SqlDataAdapter("stpGetEmpDetails", sqlConnection1); da.SelectCommand.CommandType = CommandType.StoredProcedure; workParam = new SqlParameter("@pEmpNum", System.Data.SqlDbType.VarChar); workParam.Direction = ParameterDirection.Input; workParam.Value = txtEmpNum.Text; da.SelectCommand.Parameters.Add(workParam); ds = new DataSet(); da.Fill(ds, "dbo.pdp_emp"); txtDirectorate.Visible = true; lblDirectorate.Visible = true; txtDept.Visible = true; lblDept.Visible = true; txtName.Visible = true; lblName.Visible = true; txtDirectorate.Text = (string) ds.Tables[0].Rows[0]["Directorate"].ToString().Trim(); txtDept.Text = (string) ds.Tables[0].Rows[0]["Department"].ToString().Trim(); txtName.Text = (string) ds.Tables[0].Rows[0]["EmpName2"].ToString().Trim(); lblTrainNeeds.Visible = true; lblTime.Visible = true; lblCosts.Visible = true; TextBox1.Visible = true; TextBox2.Visible = true; TextBox3.Visible = true; TextBox4.Visible = true; TextBox5.Visible = true; TextBox6.Visible = true; TextBox7.Visible = true; TextBox8.Visible = true; TextBox9.Visible = true; TextBox10.Visible = true; TextBox11.Visible = true; TextBox12.Visible = true; TextBox13.Visible = true; TextBox14.Visible = true; TextBox15.Visible = true; TextBox16.Visible = true; DropDownList1.Visible = true; DropDownList2.Visible = true; DropDownList3.Visible = true; DropDownList4.Visible = true; DropDownList5.Visible = true; DropDownList6.Visible = true; DropDownList7.Visible = true; DropDownList8.Visible = true; btnSave.Visible = true; } private void btnSave_Click(object sender, System.EventArgs e) { string vEmpNum = txtEmpNum.Text; string vTrainNeeds = TextBox1.Text; string vTime = DropDownList1.SelectedItem.Value.ToString(); float fCost = Convert.ToInt32(TextBox9.Text); insertUser(vEmpNum, vTrainNeeds, vTime, fCost); } private void insertUser(string vEmpNum, string vTrainNeeds, string vTime, float fCost){ //Create parameters SqlParameter Parm1 = new SqlParameter("@pEmpNum",vEmpNum); SqlParameter Parm2 = new SqlParameter("@pTrainNeeds",vTrainNeeds); SqlParameter Parm3 = new SqlParameter("@pTime",vTime); SqlParameter Parm4 = new SqlParameter("@pCost",fCost); sqlConnection1.Open(); //Create SQLCommand SqlCommand cmd = new SqlCommand("stpInsertUser", sqlConnection1); //Add parameters to the SQL Command cmd.Parameters.Add(Parm1); cmd.Parameters.Add(Parm2); cmd.Parameters.Add(Parm3); cmd.Parameters.Add(Parm4); //Set the Command Type to Storeed Procedure cmd.CommandType = CommandType.StoredProcedure; //Execute stored Procedure cmd.ExecuteNonQuery(); } Quote
Heiko Posted March 10, 2004 Posted March 10, 2004 What exactly is your problem ? In your example you seem to store just one of the possibly eight training needs. Obviously, a primary key can only be used once. How is your database designed? Are you working on two tables ? One with the employees and one with the trainings? Or is it all compressed into one table? (Not recommended) Quote .nerd
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.