且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过c#和sql server中的查询查询结果的差异

更新时间:2023-02-17 17:23:52

我在测试应用程序上执行了相同的代码。它在应用程序中也给我相同的结果在sql。



它为我提供了相同的结果。只有我在代码中更改的内容是:

1。 SqlCommand comm = new SqlCommand(query, conn ); :而不是字符串变量我把SqlConnection conn的对象。

2。 conn.Open()

3。 conn.Close()



如下所述:



I executed same code on my test application. It gives me same result in application as well in sql.

it provides me the same result. Only the thing i changed in your code is :
1. SqlCommand comm = new SqlCommand(query, conn); : instead of string variable i put the object of SqlConnection conn.
2. conn.Open()
3. conn.Close()

as mentioned below :

string con = ConfigurationSettings.AppSettings["DBConnectionString"];
SqlConnection conn = new SqlConnection(con);
conn.Open();
string query = "select name from sysdatabases(nolock)";
SqlCommand comm = new SqlCommand(query, conn);
SqlDataReader dr = comm.ExecuteReader();
conn.Close();


感谢您关注他们..



不做任何改动代码或连接字符串现在代码运行正常,不知道为什么它之前显示错误的输出.. :)

接受这个作为一个答案将其从未答复中删除..
Thanks for showing concern guys..

Without making any changes in code or connection string now code is running fine, don't know why it was showing wrong output earlier.. :)
Accepting this as an answer to remove it from unanswered..