how avoid duplicate data before inserting. used below code i'm getting error.
no column name specified column 1 of 'temp'.
no column name specified column 2 of 'temp'.
no column name specified column 3 of 'temp'.
no column name specified column 4 of 'temp'.
no column name specified column 5 of 'temp'.
no column name specified column 6 of 'temp'.
no column name specified column 8 of 'temp'.
no column name specified column 9 of 'temp'.
invalid column name 'datelist'.
using (sqlconnection con2 = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring)) { var fromdate = datetime.parse(txtfromdate.text); var todate = datetime.parse(txttodate.text); var datedif1 = (todate - fromdate).days; var sqlinsert = new sqlcommand("insert datelist ([datedif],[batch],[daywk],[semester],[weekbatch],[subject],[facultyname],[facultyid],[weekmonth]) select * (select @datedif,@batch,@daywk,@semester,@weekbatch,@subject,@facultyname,@facultyid,@weekmonth) temp not exists (select datelist,batch datelist batch=@batch , datedif=@datedif)", con2); var sqlparamater = sqlinsert.parameters.add("@datedif", sqldbtype.date); var sqlparameter1 = sqlinsert.parameters.add("@batch", sqldbtype.nvarchar); var sqlparameter2 = sqlinsert.parameters.add("@daywk", sqldbtype.nvarchar); var sqlparameter3 = sqlinsert.parameters.add("@semester", sqldbtype.nvarchar); var sqlparameter4 = sqlinsert.parameters.add("@weekbatch", sqldbtype.nvarchar); var sqlparameter5 = sqlinsert.parameters.add("@subject", sqldbtype.nvarchar); var sqlparameter6 = sqlinsert.parameters.add("@facultyname", sqldbtype.nvarchar); var sqlparameter7 = sqlinsert.parameters.add("@facultyid", sqldbtype.nvarchar); var sqlparameter8 = sqlinsert.parameters.add("@weekmonth", sqldbtype.nvarchar); con2.open(); // try //{ (var = 0; <= datedif1; i++) { var consecutivedate = fromdate.adddays(i); sqlparamater.value = consecutivedate; sqlparameter1.value = batch1; sqlparameter2.value = dayweek; sqlparameter3.value = semester; sqlparameter4.value = weekbatch; sqlparameter5.value = subject; sqlparameter6.value = faculty; sqlparameter7.value = facultyid; sqlparameter8.value = weekmonth; int s = sqlinsert.executenonquery(); } }
i'll admit not having tested this, given error message, subquery:
select @datedif, @batch, -- , on @weekmonth ) temp
needs have column names defined, value comes variable.
that be:
select @datedif datedif, @batch batch, -- , on @weekmonth weekmonth ) temp
Comments
Post a Comment