The label 'Count' has already been declared. Label names must be unique within a query batch or stored procedure.
Im inserting multiple values from a screen on button click event, but im getting below error multiple times..
The label 'Count' has already been declared. Label names must be unique within a query batch or stored procedure.The label 'Text' has already been declared. Label names must be unique within a query batch or stored procedure.
Can anyone explain me the reason behind this error? My code is right below. Thank You in advance
I regret if im not clear.
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=SAHS;Integrated Security=True;MultipleActiveResultSets=true"); SqlCommand cmd = new SqlCommand("insert into StudentMaster(pk_id,GrNo,Name,DOB,Std,Div,RollNo,MobileNo,Address,TelNo,FathersName,FathersProfession,MothersName,MothersProfession,Age,Year,status,DOE,BookNo,FeesStatus,FthrsQlfction,FthrsOfcAdd,FthrsPhone,MthrsPhone,MthrsOfcAdd,MthrsQlfction,Bloodgrp,caste,Nationality,MotherTongue,PreviousSchool,Religion,height,weight,StdtImage,sex,SCode)values ("+ txt_Grno.Text + "," + txt_name + "," + dateTimePicker2.Value + "," + cb_class + "," + cb_div + "," + txt_roll + "," + txt_mobile + "," + Rtxt_ResiAdd + "," + txt_Phone + "," + txt_fname + "," + txt_fOccu + "," + txt_mName + "," + txt_mOccu + "," + txt_Age + ",getDate()," + cb_status + "," + dateTimePicker1.Value + "," + txt_bookno + "," + cb_feestat + "," + txt_fQualificatn + "," + Rtxt_fOfcAdd + "," + txt_fPhone + "," + txt_mPhone + "," + Rtxt_mOfcAdd + "," + txt_mQualificatn + "," + cb_BldGrp + "," + txt_caste + "," + txt_Nationality + "," + txt_MthrTng + "," + txt_PrevSchool + "," + txt_Relgn + "," + txt_hgt + "," + txt_weight + ","+pictureBox1.Image+"," + cb_Gender + ",studentcode", con); /*//SAve image from Picturebox into memory stream object MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, ImageFormat.Jpeg); //Read from Memory Stream object into ByteArray Byte bytPicdata = new Byte[ms.Length]; ms.Position = 0; ms.Read(bytPicdata, 0, Convert.ToInt32(ms.Length)); //Create parameter for the insert statement that contains image SqlParameter prm = new SqlParameter("@Picdata", SqlDbType.VarBinary, bytPicdata.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bytPicdata); cmd.Parameters.Add(prm);*/ con.Open(); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("inserted successfully"); }
- Moved by Dave PatrickMVP Friday, August 16, 2013 10:49 PM
First step is to add a parameter for each value in the value section of the SQL statement, not just for the image bytes. Also use & rather than + when using string concatenation. I advise using implicit parameters where you specify the column type rather than using AddWithValue which has at least a one percent chance of getting the type wrong and with a statement this large that is too much so use the Add method and specify parameter types
Now attempt to run the SQL, if there are still errors post the revised code here.
On a side note, you might consider revising your table design i.e. split out phone numbers and set a relationship between the tables along with a reference table for types of relations between people as of right now you have two phone numbers and perhaps in the future need home, cell and work for each person, instead of adding additional fields to the main table you add records to the phone table. I did see a mobile number but that is also limiting. Also spell out field names i.e. if someone looked at your field names it might be difficult to determine what MthrsOfcAdd is.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
- Marked as answer by Barry WangMicrosoft contingent staff, Moderator Wednesday, August 28, 2013 1:33 AM