62,046
社区成员
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();
}
}
}
说实话,你都能把代码贴出来了,为什么不实用DEBUG模式跟踪下看看问题出在哪里呢?
你可以先在debug模式,先把要执行的sql脚本解析出来,然后在数据库里面执行一下,看是不是正确。
你现在da.Fill(dt, "pz");这里的语法不对。