c# - Syntax for 2 sql connections in a return statement -
i have grid view being populated 1 connected table. code below:
private void bindgridcontent() { datatable dtinfo = getcontent(); if (dtinfo.rows.count > 0) { // bind data uxnoticegv.datasource = dtinfo; uxnoticegv.databind(); // show gridview uxnoticegv.visible = true; // hide grid message uxgridmessagelbl.visible = false; } else { // hide gridview uxnoticegv.visible = false; // display grid message uxgridmessagelbl.visible = true; } uxgridviewheader.setgridviewheader(uxnoticegv, dtinfo.rows.count); }
the issue i'm having current table doesn't have description of fields i'm returning in gridview. id values being displayed instead. can't join table unless create linked server, don't have permission do. (linked server answers ruled out)
below data access class(layer returns current table):
public static datatable viewlogsearch(string linenumber, datetime createddatebegin, string detailpurposeorfunction, string connectiontypedesc, datetime createddateend, string machineserverconnection) { var sqlstatement = new stringbuilder(); sqlstatement.append(" select"); sqlstatement.append(" ae.accountentryid, ae.lastupdatedby, ae.purposeorfunctiondialindesc, ae.physicallocationdesc, "); sqlstatement.append(" ae.purposeorfunctiondialoutdesc, ae.passwordchangefrequency, ae.otherlayerauthenticationdesc, "); sqlstatement.append(" ae.typeofconnectionid, ae.createddate, ct.connectiontypedesc,"); sqlstatement.append(" ae.linenumber, ae.detailpurposeorfunction"); sqlstatement.append(" from"); sqlstatement.append(" dbo.accountentry ae"); //added after sqlstatement.append(" join"); sqlstatement.append(" dbo.connectiontype ct"); sqlstatement.append(" on ae.typeofconnectionid = ct.connectiontypeid"); sqlstatement.append(" 1=1 "); // sql parameter collection var sqlparams = new list<sqlparameter>(); // commented out excess logic passing parameters // create sql command var sqlcmd = new sqlcommand(sqlstatement.tostring()); // add sql parameters sql command sqlcmd.parameters.addrange(sqlparams.toarray()); // execute sql return dbaccess.sqlserver.getdatatable(dbaccess.sqlserver.getconnectionstring("accountdb"), sqlcmd); }
i can query other database. i'm thinking i'll query other database , return field i'm interested in. entail have 2 connection strings.
any ideas on how create 2 connection strings 1 method? please note joined table not table i'm interested in bringing in. i'm open other approaches issue. please provide psuedo code.
since are loading datatables, better approach might keep 2 separate functions - 1 each set of data. in keeping single responsibility principle (srp), encouragement keep small functions 1 job each.
third functions calls 2 , uses linq join data. see this post more on datatable joins.
Comments
Post a Comment