C# 调用存储过程

    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#,c#,java,服务器)