大家好,我有这个 SqlDataAdapter 可以找到最高值:
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("Select MAX (ID_K) FROM klient", spojeni);
SDA.Fill(dt);
spojeni.Close();
如果它选择我需要它的结果,请添加 +1 并将其作为对象值插入到此参数中。
prikaz2.Parameters.AddWithValue("@val4", ); // here should be SDA +1
我试图将整个 SqlDataAdapter 插入到对象值中,但这是胡说八道。有什么办法可以实现吗?
提前致谢
最佳答案
您可以使用 SqlCommand.ExecuteScalar()
获取此值的方法,因为;
Executes the query, and returns the first column of the first row in the result set returned by the query.
由于您的命令仅返回 ID_K
列的最大值,这正是我们想要的。
SqlCommand command = new SqlCommand("Select MAX (ID_K) FROM klient");
SqlDataAdapter SDA = new SqlDataAdapter(command, spojeni);
int max = (int)command.ExecuteScalar();
prikaz2.Parameters.AddWithValue("@val4", max + 1);
关于c# - SqlDataAdapter 作为对象值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700004/