//Initialize the provider and connection string functions of the SQL data source OK Public Virtual voidinitsqldatasource_constr (SqlDataSource sql_ds) {connectionstringsettings Cs_set= configurationmanager.connectionstrings["connstring"]; Sql_ds. ProviderName=Cs_set. ProviderName; Sql_ds. ConnectionString=Cs_set. ConnectionString; } //initialize the SQL data source query Insert Modify statement for a primary key field name Public Virtual voidInitsqldatasource_selectinsertupdate (SqlDataSource P_ds,stringGridview_controlid,stringTableName,stringWHERE_STR,stringkeyfieldname) { stringx =""; //ControlParameter Ctrl_param =NewControlParameter (); Ctrl_param. ControlID=Gridview_controlid; Ctrl_param. PropertyName="Keyfieldname"; Ctrl_param. Name=Keyfieldname; // stringT_fd_name =""; X="SELECT * from"+ TableName +"where 1<>1"; DataTable Dt_null= This. Getdatatable (x); // stringFds_str =""; stringFds_val =""; stringUpdate_fds_str =""; //Get field Parse post string This. GET_SQLDATASOURCE_SQL_STR (TableName,refFDS_STR,refFds_val,refupdate_fds_str); // stringInsert_sql =""; Insert_sql="Insert"+ TableName +"("+ Fds_str +") VALUES ("+ Fds_val +")"; stringUpdate_sql =""; Update_sql="Update"+ TableName +"Set"+ Update_fds_str +"where"+ Keyfieldname +"[email protected]"+ Keyfieldname +" "; //Query StatementsP_ds. Selectcommandtype =Sqldatasourcecommandtype.text; P_ds. SelectCommand="SELECT * from"+ TableName +" "+Where_str; // ////DELETE statementP_ds. Deletecommandtype =Sqldatasourcecommandtype.text; P_ds. DeleteCommand="Delete from"+ TableName +"where"+ Keyfieldname +"[email protected]"+ Keyfieldname +""; P_ds. Deleteparameters.clear (); P_ds. Deleteparameters.add (Ctrl_param); // //INSERT StatementP_ds. Insertcommandtype =Sqldatasourcecommandtype.text; P_ds. InsertCommand=Insert_sql; P_ds. Insertparameters.clear (); P_ds. Insertparameters.add (Ctrl_param); //-- for(inti =0; I < Dt_null. Columns.count; i++) {T_fd_name=Dt_null. Columns[i]. ColumnName; if(T_fd_name. ToUpper ()! =keyfieldname) {P_ds. Insertparameters.add (NewParameter (t_fd_name)); } } // //Modifying statementsP_ds. Updatecommandtype =Sqldatasourcecommandtype.text; P_ds. UpdateCommand=Update_sql; //--P_ds. Updateparameters.clear (); P_ds. Updateparameters.add (Ctrl_param); for(inti =0; I < Dt_null. Columns.count; i++) {T_fd_name=Dt_null. Columns[i]. ColumnName; if(T_fd_name. ToUpper ()! =keyfieldname) {P_ds. Updateparameters.add (NewParameter (t_fd_name)); } } //== } Public Virtual voidInitsqldatasource_select (SqlDataSource P_ds,stringTableName,stringwhere_str) { //Query StatementsP_ds. Selectcommandtype =Sqldatasourcecommandtype.text; P_ds. SelectCommand="SELECT * from"+ TableName +" "+Where_str; // //==}
//get the SQL data source update and INSERT statements required by the combined string function OK Public voidGET_SQLDATASOURCE_SQL_STR (stringTableNameref stringFDS_STR,ref stringFds_val,ref stringupdate_fds_str) { stringx ="SELECT * from"+tablename+"where 1<>1"; DataTable Dt_null= This. Getdatatable (x); stringT_fd_name =""; Fds_str=""; Fds_val=""; //Update_fds_str =""; // for(inti =0; I < Dt_null. Columns.count; i++) {T_fd_name=Dt_null. Columns[i]. ColumnName; //#region//INSERT statement string processing if(Fds_str = ="") {Fds_str=T_fd_name; Fds_val="@"+T_fd_name; } Else{fds_str+=","+T_fd_name; Fds_val+=",@"+T_fd_name; } //#endregion//#region//Modifying statement string processing if(Update_fds_str = ="") {Update_fds_str= T_fd_name +"[email protected]"+T_fd_name; } Else{update_fds_str+=","+ T_fd_name +"[email protected]"+T_fd_name; } //#endregion } } //
Method to invoke:
// initializing the data source for requirement information registration this. Initsqldatasource_constr (this. sql_ds_xq); string this. dx_gv_xq.id; // or Xq_ctrlid =this.pagecontrol.id+ "$" + This.dx_gv_xq.ID; this. Initsqldatasource_selectinsertupdate (this"TableName"" Mainfieldname ");
DevExpress methods for initializing SQL data sources in post code