string connstr = ""; //这里输入你的数据库连接信息
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Proc_GetBillNo"; //这里是你的存储过程名称
cmd.Parameters.Add(new SqlParameter("@BillType", SqlDbType.VarChar, 10)); //这是你的存储过程的参数
cmd.Parameters.Add(new SqlParameter("@TableName", SqlDbType.VarChar, 50));
cmd.Parameters.Add(new SqlParameter("@FieldName", SqlDbType.VarChar, 50));
cmd.Parameters["@BillType"].Value = "GYCG";
cmd.Parameters["@TableName"].Value = "Purchase_Order";
cmd.Parameters["@FieldName"].Value = "BillNo";
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt.Rows[0][0].ToString();
}
}
C# 调用存储过程
最新推荐文章于 2024-04-17 17:59:27 发布