62,046
社区成员
发帖
与我相关
我的任务
分享
string insertstr = "insert into CTXS(ctid,time,yye,kds,xfrs,kdj,rjxf,jlxs) select N001 as ctid, @t as time,(select sum(cpje) from YSXS1 where ctid= N001 and time= @t) as yye,(select kdsl from YSXS2 where ctid= N001 and time= @t) as kds,(select xfrs from YSXS2 where ctid= N001 and time= @t)as xfrs,(select sum(cpje) from YSXS1 where ctid= N001 and time= @t)*1.00/(select kdsl from YSXS2 where ctid= N001 and time= @t) as kdj,(select sum(cpje) from YSXS1 where ctid= N001 and time= @t)*1.00/(select xfrs from YSXS2 where ctid= N001 and time= @t) as rjxf,(select sum(cpje) from YSXS1,CPXX where CPXX.cpid=YSXS1.cpid and CPXX.gdfl=鸡类 and ctid=N001 and time=@t)as jlxs;";
尼玛 你弄一行 肯定没错了...
protected void Button8_Click(object sender, EventArgs e)
{
String constr = "Data Source=localhost;Integrated Security=False;Initial Catalog=Lxj;User ID=sa;Password=sa";
SqlConnection conn = new SqlConnection(constr); //创建链接
conn.Open(); //打开链接
//创建数据库操作语句
下面这句你好像都没用到
String cmdstr = "select * from YSXS1 where time='" + T.Text.Trim() + "'";
string 年月 = T.Text.Trim();
string insertstr = @" INSERT INTO CTXS (ctid
, TIME
, yye
, kds
, xfrs
, kdj
, rjxf
, jlxs)
SELECT 'N001' AS ctid
, @t AS TIME
, (SELECT sum (cpje)
FROM YSXS1
WHERE ctid = 'N001' AND TIME = @t) AS yye
, (SELECT kdsl
FROM YSXS2
WHERE ctid = 'N001' AND TIME = @t) AS kds
, (SELECT xfrs
FROM YSXS2
WHERE ctid = 'N001' AND TIME = @t) AS xfrs
, (SELECT sum (cpje)
FROM YSXS1
WHERE ctid = 'N001' AND TIME = @t) * 1.00 / (SELECT kdsl
FROM YSXS2
WHERE ctid = 'N001' AND TIME = @t) AS kdj
, (SELECT sum (cpje)
FROM YSXS1
WHERE ctid = 'N001' AND TIME = @t) * 1.00 / (SELECT xfrs
FROM YSXS2
WHERE ctid = 'N001' AND TIME = @t) AS rjxf
, (SELECT sum (cpje)
FROM YSXS1
, CPXX
WHERE CPXX.cpid = YSXS1.cpid AND CPXX.gdfl = '鸡类' AND ctid = 'N001' AND TIME = @t) AS jlxs;";
SqlCommand cmd = new SqlCommand(insertstr, conn);
//插入SQL语句里面有@t,所以加了个参数,具体的值根据需要改一下
cmd.Parameters.Add("t", 年月);
//int ret = cmd.ExecuteNonQuery();
//执行插入语句
cmd.ExecuteNonQuery();
string strSQL = "select CTXS.* from CTXS where time = @t";
SqlDataAdapter myAdapter = new SqlDataAdapter(strSQL, conn);
DataSet myDS = new DataSet();
myAdapter.SelectCommand.Parameters.Add(new SqlParameter("@t", SqlDbType.Char, 6));
myAdapter.SelectCommand.Parameters["@t"].Value = 年月;
myAdapter.Fill(myDS, "CTXS");
dataGridView1.DataSource = null;
dataGridView1.DataSource = myDS;
dataGridView1.DataBind();
dataGridView1.Visible = true;
conn.Close();
}
protected void Button8_Click(object sender, EventArgs e)
{
String constr = "Data Source=localhost;Integrated Security=False;Initial Catalog=Lxj;User ID=sa;Password=sa";
SqlConnection conn = new SqlConnection(constr); //创建链接
conn.Open(); //打开链接
//创建数据库操作语句
String cmdstr = "select * from YSXS1 where time='" + T.Text.Trim() + "'";
string 年月 = T.Text.Trim();
string insertstr = @"insert into CTXS(ctid,time,yye,kds,xfrs,kdj,rjxf,jlxs)
select N001 as ctid, @t as time,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t) as yye,(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kds,(select xfrs from YSXS2 where
ctid= N001 and time= @t)as xfrs,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kdj,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select xfrs from YSXS2 where
ctid= N001 and time= @t) as rjxf,(select sum(cpje)
from YSXS1,CPXX where CPXX.cpid=YSXS1.cpid
and CPXX.gdfl=鸡类 and ctid=N001 and time=@t)as jlxs;";
SqlCommand cmd = new SqlCommand(insertstr, conn);
string strSQL = "select CTXS.* from CTXS where time = @t";
SqlDataAdapter myAdapter = new SqlDataAdapter(strSQL, conn);
DataSet myDS = new DataSet();
myAdapter.SelectCommand.Parameters.Add(new SqlParameter("@t", SqlDbType.Char, 6));
myAdapter.SelectCommand.Parameters["@t"].Value = 年月;
myAdapter.Fill(myDS, "CTXS");
GridView1.DataSourceID = null;
GridView1.DataSource = myDS;
GridView1.DataBind();
GridView1.Visible = true;
conn.Close();
这样倒是没错误但是点击按钮后没有反应啊,数据库也没有变化。。。请大神给看看,语句是不是有错误。我是需要把查询的数据放入另一个表,然后再把这个表中的数据利用GridView 呈现string insertstr = @"insert into CTXS(ctid,time,yye,kds,xfrs,kdj,rjxf,jlxs) VALUES
select N001 as ctid, @t as time,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t) as yye,(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kds,(select xfrs from YSXS2 where
ctid= N001 and time= @t)as xfrs,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kdj,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select xfrs from YSXS2 where
ctid= N001 and time= @t) as rjxf,(select sum(cpje)
from YSXS1,CPXX where CPXX.cpid=YSXS1.cpid
and CPXX.gdfl=鸡类 and ctid=N001 and time=@t)as jlxs;";
string insertstr = @"insert into CTXS(ctid,time,yye,kds,xfrs,kdj,rjxf,jlxs)
select N001 as ctid, @t as time,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t) as yye,(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kds,(select xfrs from YSXS2 where
ctid= N001 and time= @t)as xfrs,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select kdsl from YSXS2 where
ctid= N001 and time= @t) as kdj,(select sum(cpje) from YSXS1 where
ctid= N001 and time= @t)*1.00/(select xfrs from YSXS2 where
ctid= N001 and time= @t) as rjxf,(select sum(cpje)
from YSXS1,CPXX where CPXX.cpid=YSXS1.cpid
and CPXX.gdfl=鸡类 and ctid=N001 and time=@t)as jlxs;";