c#sql返回值

来源:百度知道 编辑:UC知道 时间:2024/06/27 04:09:22
我定义一个参数 int m
然后查询数据库 table 最后一条记录 字段xxx的值
然后让m等于最后一条记录字段xxx的值应该怎么写呀。。高手们教教我。

不知道你要的是不是存储过程
create procedure OutInt
(
@obID varchar(50),
@OutInt int output)
as
select @OutInt=Msgid from tables where obID=@obID
print @OutInt;
return @OutInt;
go
经测试能返回int值

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string xxx = new Sql().Sel();
}
}
class Sql
{
SqlConnection conn = new SqlConnection();//加上你的连接字符串
public string Sel()
{
SqlCommand cmd = new SqlCommand("查询字符串", conn);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataSet ds=new DataSet();
adapter.Fill(ds);