public void update_part(sqlParameters ssp, string updateData) { List <string> parametersRAW = new List <string>( ); for (int i = 0; i < spec.partTxSpec.Count - 1; i++) { part = _switch.partSwitchFromQB(i, updateData.Substring(position, spec.partTxSpec[i]), part); position += spec.partTxSpec[i]; } SqlCommandBuilder scb; DataSet ds = new DataSet( ); ssp.SQLcmd = "SELECT * FROM " + ssp.tableName + " WHERE " + ssp.searchKey + " = " + ssp.searchVal; SqlDataAdapter sda = new SqlDataAdapter(ssp.SQLcmd, ssp.db_connector); sda.Fill(ds, ssp.tableName); scb = new SqlCommandBuilder(sda); SqlCommand update = scb.GetUpdateCommand(true); update.Connection = ssp.db_connector; if (int.TryParse(ds.Tables[0].Rows[0].ItemArray[0].ToString( ), out int Id)) { update = _switch.partSwitchToSQLUpdate(update, part, Id, ds.Tables[0].Rows[0].ItemArray); } ssp.db_connector.Open( ); update.ExecuteNonQuery( ); ssp.db_connector.Close( ); }
public void insert_part(sqlParameters ssp, string insertData) { for (int i = 0; i < spec.partTxSpec.Count - 1; i++) { part = _switch.partSwitchFromQB(i, insertData.Substring(position, spec.partTxSpec[i]), part); position += spec.partTxSpec[i]; } DataSet ds = new DataSet( ); SqlCommandBuilder scb; SqlDataAdapter sda = new SqlDataAdapter(ssp.SQLcmd, ssp.db_connector); sda.Fill(ds, ssp.tableName); scb = new SqlCommandBuilder(sda); SqlCommand insert = scb.GetInsertCommand(true); insert.Connection = ssp.db_connector; if (part.part_name.Trim( ) != null) { insert = _switch.partSwitchToSQLInsert(insert, part); ssp.db_connector.Open( ); insert.ExecuteNonQuery( ); ssp.db_connector.Close( ); } }