Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view that is being populated from 1 table, code below:
#region Bind Grid Content
       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);
       }
       #endregion


My question: Is it possible for uxNoticeGv to have multiple datasources? I ask because as of right now one of my gridview columns is being populated with an id value and I need the description. That would entail that I create a linked server, which I don't have the permissions to do.

I can however, query and return data from the other data source. I just need to have uxNoticeGv have 2 data sources if possible.

Any ideas on how to tackle this issue.


Current SQL Connection Code
C#
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.DataBeingTransferredDesc, ae.PurposeOrFunctionDialInDesc, ae.PhysicalLocationDesc, ");
           sqlStatement.Append("   ae.PurposeOrFunctionDialOutDesc, ae.ApplicationUtilizingModemDesc, ae.PasswordChangeFrequency, ae.OtherLayerAuthenticationDesc, ");
           sqlStatement.Append("   ae.MachineServerModeConnectionDesc, 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(" WHERE 1=1 ");

           // SQL parameter collection
          var sqlParams = new List<SqlParameter>();
           // Check if Line Number was passed
          if (lineNumber.Trim().Length > 0)
          {
              sqlStatement.Append("   and ae.LineNumber = @LineNumber");
              sqlParams.Add(new SqlParameter() { ParameterName = "@LineNumber", SqlDbType = SqlDbType.Int, Value = lineNumber });
          }
           // Check if purposeOrFunctionDialInDescLike was passed
          if (detailPurposeOrFunction.Trim().Length > 0)
          {
              sqlStatement.Append("    and ae.DetailPurposeOrFunction like @DetailPurposeOrFunction");
              sqlParams.Add(new SqlParameter() { ParameterName = "@DetailPurposeOrFunction", SqlDbType = SqlDbType.VarChar, Size = 70, Value = DBDataHelper.FormatStringLike(detailPurposeOrFunction) });
          }
          // Check if typeOfConnectionDescLike was passed
          if (connectionTypeDesc.Trim().Length > 0)
           {
               sqlStatement.Append("   and ct.ConnectionTypeDesc Like @ConnectionTypeDescLike");
               sqlParams.Add(new SqlParameter() { ParameterName = "@ConnectionTypeDescLike", SqlDbType = SqlDbType.VarChar, Size = 50, Value = DBDataHelper.FormatStringLike(connectionTypeDesc) });
           }
           // Entered Date Begin
          if (createdDateBegin != DateTime.MaxValue)
           {
               sqlStatement.Append("   and ae.CreatedDate >= @CreatedDateLike");
               sqlParams.Add(new SqlParameter() { ParameterName = "@CreatedDateLike", SqlDbType = SqlDbType.Date, Value = createdDateBegin });
           }
           // Entered Date End
          if (createdDateEnd != DateTime.MaxValue)
           { // Add 24 hours to include the full day (SQL is less than)
               createdDateEnd = createdDateEnd.AddDays(1);

               sqlStatement.Append("   and ae.CreatedDate < @EntryDateEnd");
               sqlParams.Add(new SqlParameter() { ParameterName = "@EntryDateEnd", SqlDbType = SqlDbType.DateTime, Value =  createdDateEnd});
           }
           //Machine Server Connection
          if (machineServerConnection.Trim().Length > 0)
          {
              sqlStatement.Append("    and ae.MachineServerModeConnectionDesc Like @MachineServerModeConnectionDesc");
              sqlParams.Add(new SqlParameter() { ParameterName = "@MachineServerModeConnectionDesc", SqlDbType = SqlDbType.VarChar, Size = 51, Value = DBDataHelper.FormatStringLike(machineServerConnection) });
          }
           // Create sql command
           var sqlCmd = new SqlCommand(sqlStatement.ToString());

           // Add sql parameters to sql command
           sqlCmd.Parameters.AddRange(sqlParams.ToArray());

           // Execute sql
           return DBAccess.SQLServer.GetDataTable(DBAccess.SQLServer.GetConnectionString("AccountDB"), sqlCmd);
       }
Posted
Updated 7-Aug-15 5:38am
v3

1 solution

What you need is query the data from two servers and create a single data source using both the results and assign to GV.
 
Share this answer
 
v2
Comments
Member 11820531 7-Aug-15 11:35am    
Sounds like a good idea. Would I then have 2 return statements for each connection string? I've add my current code that I'm using to return my first table.

From what I understand though, your saying: query both tables within the same method correct?
John C Rayan 7-Aug-15 11:53am    
Yeah, you need to build the collections first from two data sources. Remember to have an identifier to match both the collections and then build the data source.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900