output和return在C#程序中用法output和return在C#程序中用法
private void buzeshouduan()
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("gaoproc4", conn);
comm.CommandType = CommandTy...
output和return在C#程序中用法
private void buzeshouduan()
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("gaoproc4", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@id", Convert.ToInt32(this.textBox1.Text));
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 存储过程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("procReturn", conn);
comm.Parameters.Add("@id", Convert.ToInt32(this.textBox1.Text));
SqlParameter sp3 = comm.Parameters.Add("@returnValue", SqlDbType.Int);
sp3.Direction = ParameterDirection.ReturnValue; //自定义一个参数,用
于接受返回数据 数据的类型是接受return 返回值
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
comm.ExecuteNonQuery(); //执行命令
int n = (int)comm.Parameters["@returnValue"].Value;//获取存储过程返回
的值
if(n>0) //如果又返回值
buzeshouduan();
else
MessageBox.Show("访问用户不存在");
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("gaoproc1", conn);
comm.CommandType = CommandType.StoredProcedure;//转化成为使用存储过程
执行方法
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
///
/// 将数据读到DataGridview中
///
private void buzeshouduan()
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("gaoproc4", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@id", Convert.ToInt32(this.textBox1.Text));
SqlDataAdapter da = new SqlDataAdapter();//定义一个数据适配器 用于读
取一整个表(select 查询的结果)的数据
da.SelectCommand = comm;
DataSet ds = new DataSet();//定义一个数据表集,用于接受读取的表
da.Fill(ds,"users");//使用适配器填充数据表,并给该表起一个叫users的
表明
this.dataGridView1.DataSource = ds.Tables["users"].DefaultView;//给
dataGridView1指定数据源
}
private void button2_Click(object sender, EventArgs e)
{
changshi();
}
///
/// 使用out返回值的接受形式
///
private void changshi()
{
SqlConnection conn = new SqlConnection("Data Source=LENOVO-DA8D6034\\SONG;Initial Catalog=存储过程;Integrated Security=True");
SqlCommand comm = new SqlCommand("procOut", conn);
comm.Parameters.Add("@id", Convert.ToInt32(this.textBox1.Text));
SqlParameter sp3 = comm.Parameters.Add("@out", SqlDbType.Int);
sp3.Direction = ParameterDirection.Output;//自定义一个参数,用于接受
返回数据 数据的类型是接受out 返回值
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
comm.ExecuteNonQuery();
int n = (int)comm.Parameters["@out"].Value;
if (n > 0)
buzeshouduan();
else
MessageBox.Show("访问用户不存在");
}
}
}
本文档为【output和return在C#程序中用法】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。