小编محم*_*رضا的帖子

一个带两个连接字符串的sql命令

我想在C#中运行此查询

SELECT *
FROM [FirstDataBase].[dbo].[table1]
INNER JOIN [SecondDataBase].[dbo].[table2]
Run Code Online (Sandbox Code Playgroud)

我的代码是:

SqlConnection cn = new SqlConnection(myConnectionString);
SqlCommand cmd = new SqlCommand(@"SELECT * FROM [FirstDataBase].[dbo].[table1]
    INNER JOIN [SecondDataBase].[dbo].[table2]");

cmd.Connection = cn; // here is my question !!!

cn.Open();
int x = (int)cmd.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)

但是我的查询需要两个连接字符串...一个用于[FirstDataBase],第二个用于[SecondDataBase] ...我怎么能这样做?如何插入两个SqlConnectionConnectionString一个SqlCommand?或者我怎么能以其他方式做到这一点?

c# sql sql-server sqlcommand inner-join

4
推荐指数
2
解决办法
6502
查看次数

在 Typescript 中键入键值对对象并保存对象的键

我在以下示例中有键值对对象


interface ItemType {
    a: number;
    b: string;
}

const list = {
    first: {a: 1, b: 'one'},
    second: {a: 2, b: 'two'},
    third: {a: 3, b: 'three'},
} as { [key in keyof typeof list]: ItemType }

Run Code Online (Sandbox Code Playgroud)

但它会引发诸如TS2313: Type parameter 'key' has a circular constraint..

我希望所有项目的类型为ItemType,但仍希望列表保存我插入的键。如果我将它转换为{ [key in string]: ItemType },我将丢失列表的键名。:(

typescript

2
推荐指数
1
解决办法
107
查看次数

标签 统计

c# ×1

inner-join ×1

sql ×1

sql-server ×1

sqlcommand ×1

typescript ×1