无法从"string"转换为"System.Data.SqlClient.SqlCommand”

TerraRestore TerraRestore 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;     // 引用配置文件
using System.Data.SqlClient;    // 引用数据库操作文件

namespace 大家杯
{
    public partial class 凭证 : Form
    {
        public string pzh;   // 定义全局变量:凭证号
        public DateTime rq;   // 定义全局变量:日期

        public 凭证()
        {
            InitializeComponent();
        }

        private void 凭证_Load(object sender, EventArgs e)
        {
            if (rq != null && pzh != null)
            {
                t_pzh.Text = pzh;
                t_rq.Text = rq.ToString();
                SearchPz();
            }
        }
        private void SearchPz()
        {
            // 链接数据库
            string ConString = ConfigurationSettings.AppSettings["dajiebeidb"];
            SqlConnection conn = new SqlConnection(ConString);
            conn.Open();

            // 从数据库中查找凭证明细信息(数据来自于凭证明细表:ZW_PZMXB)   
            SqlDataAdapter da = new SqlDataAdapter("select zy as 摘要,jfje as 借方金额,dfje as 贷方金额,km_name as 会计科目 from zw_pzzb as a,zw_pzmxb as b,zw_kjkmbmb as c where b.KM_CODE=c.KM_CODE and a.nkjqj=b.nkjqj and a.ykjqj=b.ykjqj and a.pzh=b.pzh and b.nkjqj='" + rq.Year + "' and b.ykjqj='" + rq.Month.ToString().PadLeft(2, '0'); +"' and a.pzh='" + pzh + "';", conn);

            // 凭证明细信息绑定到 DataGridView 中
            DataSet dt = new DataSet();
            da.Fill(dt, "pz");
            dgv_pzmx.DataSource = dt.Tables[0];

            //从数据库中查找凭证主表信息(数据来自于凭证主表:ZW_PZZB) 
            SqlCommand cmd = new SqlCommand("select fdjs,zdr,shr,jzr from zw_pzzb where rq='" + rq + "' and pzh='" + pzh + "';", conn);
            SqlDataReader reader = cmd.ExecuteReader();//返回只能读取,不能写入的SqlDataReader对象
            while (reader.Read())
            {
                t_fdjs.Text = reader["fdjs"].ToString();
                t_zdr.Text = reader["zdr"].ToString();
                t_shr.Text = reader["shr"].ToString();
                t_jzr.Text = reader["jzr"].ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pzh = t_pzh.Text;
            rq = t_rq.Text;

            SearchPz();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
    }

...全文
评论 2
收藏 已收藏
分享
返回顶部
TerraRestore
.NET社区 62,275 成员 668,968 内容