本文介绍了sql结果保存到c#变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
如何将保存到C#变量中的SQL结果保存到
请在下面纠正我的是我的代码,我必须在DeliveryOrdertable中查找总数行并将其保存到count变量.
Hi
How do i save sql result saved into c# variable
Please correct me below is my code i have to find total number rows in DeliveryOrdertable and save it to count variable.
public void autono()
{
int count;
SqlDataReader reader = null;
string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
string selectcmd = " SELECT count(*)as numberofrows FROM DeliveryOrder" ;
SqlCommand cmd = new SqlCommand(selectcmd, conn);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
count = Convert.ToInt32(reader);
conn.Close();
} }
问候
Lancy
Regards
Lancy
推荐答案
public void autono()
{
int count;
SqlDataReader reader = null;
string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
string selectcmd = " SELECT count(*)as numberofrows FROM DeliveryOrder" ;
SqlCommand cmd = new SqlCommand(selectcmd, conn);
conn.Open();
count = (int) cmd.ExecuteScalar();
}
count = reader.GetInt32(0);
这篇关于sql结果保存到c#变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!