如何使用C#在第一个数据表中添加包含数据的新列 [英] How to add new column with data in first datatable using C#

查看:296
本文介绍了如何使用C#在第一个数据表中添加包含数据的新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

My Current Dataset in Table[0]

Id  |   Name    |  City
1   |  Akshada  |  Baroda
2   |  Rutu     |  Pune







Second Dataset Table [1]
Cast
Bramhin 
Rajput 
Muslim










I Want Below Answer 

Id  |   Name    |  City    | Cast
1   |  Akshada  |  Baroda  | Bramhin
2   |  Rutu     |  Pune    | Rajput
3   |  Priya    |  Jaipur  | Muslim





我的尝试:





What I have tried:

pSqlParameter = new SqlParameter[1];

                pSqlParameter[0] = new SqlParameter("@BatchId", SqlDbType.Int);
                pSqlParameter[0].Direction = ParameterDirection.Input;
                pSqlParameter[0].Value = intBatchId;

                strStoredProcName = "usp_tbl_TestSampleResult_SelectALL_ForDisplay";                

                DataSet dsResult = new DataSet();
                dsResult = Database.ExecuteDataSet(CommandType.StoredProcedure, strStoredProcName, pSqlParameter);

                //ApplicationResult objResults = new ApplicationResult(dsResult);
                //objResults.Status = ApplicationResult.CommonStatusType.Success;
                //return objResults;


                strStoredProcNameTwo = "usp_tbl_TestSampleResult_SelectALL_ForDisplay_ParameterResult";
                DataSet dsResult1 = new DataSet();

                dsResult1 = Database.ExecuteDataSet(CommandType.StoredProcedure, strStoredProcNameTwo, pSqlParameter);
                dsResult.Merge(dsResult1);

                ApplicationResult objResults = new ApplicationResult(dsResult);
                objResults.Status = ApplicationResult.CommonStatusType.Success;
                return objResults;

推荐答案

Thank you all for helping me i got solution using below code










objResult.ResutlDs.Tables[0].Columns.Add("Cast", typeof(string));
for (int i = 0; i < objResult.ResutlDs.Tables[0].Rows.Count; i++)
{
     objResult.ResutlDs.Tables[0].Rows[i]["Cast"] = objResult.ResutlDs.Tables[2].Rows[i]["Cast"];
}


我想你必须学习inne​​rjoin,leftjoin将帮助你连接表并从第一个表中获取colume并一起显示

这是一个例子试试这个



SELECT Orders.OrderID,Customers.CustomerName

FROM Orders

INNER JOIN客户在Orders.CustomerID = Customers.CustomerID;
I guess you have to learn innerjoin,leftjoin that will help you join table and get colume from 2 table with first and display together
This is an example try this

SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;


这篇关于如何使用C#在第一个数据表中添加包含数据的新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆