我在c#2003中,我的数据库表是这样的啊!
id ProductID number datetime
1 2 21 2007-03-01
2 2 23 2007-04-01
3 2 25 2007-05-01
4 2 43 2007-06-01
5 2 31 2007-03-01
6 3 23 2007-04-01
7 3 56 2007-05-01
8 3 16 2007-06-01
然后显示出来的样子是----------------------------------------------------------------------------------
| 商品名称 | 2007-04 | 2007-05 | 2007-06 | 2007-07 | 2007-08 | 2007-09 | 2007-10 |
----------------------------------------------------------------------------------
| 2 | 23 | 25 | 43 | | | | |
----------------------------------------------------------------------------------
| 3 | 23 | 56 | 16 | | | | |
----------------------------------------------------------------------------------
日期是显示从当前月往后依次类推6个月,如果,后面的月份没有输入数据则显示空白
每个显示的数据都是在一个input文本框中的,可以进行保存修改,如果,空白的地方输入数据的话则是新增一条!从数据库中取出数据,我的语句是这样写的
select productid
, sum(case month([datetime]) when dataAdd(getdate(),0)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),1)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),2))then number end)
, sum(case month([datetime]) when dataAdd(getdate(),3)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),4)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),5)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),6)) then number end)
from products
group by productid现在问题是,保存的时候该如何解决呢?
因为,有些是原有的,我只要修改就可以拉,但是有些是新增的,该如何判断呢、
同时日期该如何存入,我是按照表头的那个月份,如果对应的是2007-5,则存入数据库的是2007-5-1,依次类推啊,该如何解决呢?
各位高手帮帮忙啊!
id ProductID number datetime
1 2 21 2007-03-01
2 2 23 2007-04-01
3 2 25 2007-05-01
4 2 43 2007-06-01
5 2 31 2007-03-01
6 3 23 2007-04-01
7 3 56 2007-05-01
8 3 16 2007-06-01
然后显示出来的样子是----------------------------------------------------------------------------------
| 商品名称 | 2007-04 | 2007-05 | 2007-06 | 2007-07 | 2007-08 | 2007-09 | 2007-10 |
----------------------------------------------------------------------------------
| 2 | 23 | 25 | 43 | | | | |
----------------------------------------------------------------------------------
| 3 | 23 | 56 | 16 | | | | |
----------------------------------------------------------------------------------
日期是显示从当前月往后依次类推6个月,如果,后面的月份没有输入数据则显示空白
每个显示的数据都是在一个input文本框中的,可以进行保存修改,如果,空白的地方输入数据的话则是新增一条!从数据库中取出数据,我的语句是这样写的
select productid
, sum(case month([datetime]) when dataAdd(getdate(),0)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),1)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),2))then number end)
, sum(case month([datetime]) when dataAdd(getdate(),3)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),4)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),5)) then number end)
, sum(case month([datetime]) when dataAdd(getdate(),6)) then number end)
from products
group by productid现在问题是,保存的时候该如何解决呢?
因为,有些是原有的,我只要修改就可以拉,但是有些是新增的,该如何判断呢、
同时日期该如何存入,我是按照表头的那个月份,如果对应的是2007-5,则存入数据库的是2007-5-1,依次类推啊,该如何解决呢?
各位高手帮帮忙啊!
, isnull(sum(case month([datetime]) when month(getdate()) then number end) ,0)
, isnull(sum(case month([datetime]) when month(getdate())+ 1 then number end) , 0)
, isnull(sum(case month([datetime]) when month(getdate())+ 2 then number end) , 0)
, isnull(sum(case month([datetime]) when month(getdate())+ 3 then number end) , 0)
, isnull(sum(case month([datetime]) when month(getdate())+ 4 then number end) , 0)
, isnull(sum(case month([datetime]) when month(getdate())+ 5 then number end) , 0)
, isnull(sum(case month([datetime]) when month(getdate())+ 6 then number end) , 0)
from products
group by productid编辑DataGrid的时候,如果原来为0的则执行插入语句,否则执行更新语句
我的想法是,取已经没有问题了!关键是保存!
页面是已经可以有数据了,
然后是把页面上的table里的数据先全部数据取出,然后在跟数据库里的数据进行对比啊!就是后面这部我不知道该如何写!
在读出数据的时候你的SQL语句改为“select *from products for XML AUTO ,ELEMENTS”
这样你取出的数据就是XML形式的,然后使用IO进行保存。
当你修改数据的时候直接操作XML文件将修改的数据保存到临时生成的一个XML文件中。
修改完成后通过ADO.NET将临时生成的XML文件中的内容读入SQLServer中。
这样无论你做多少次修改只是进行IO操作速度会比ADO.NET快点。最后将XML文件读入SQLServer的时候你的数据由于是全是修改后的数据所以无需做是否修改的判断可以直接修改(必须有一个主键作为条件,否则就新增数据了),这样还可以解决频繁使用ADO.NET产生的效率问题。
select *from products for XML AUTO ,ELEMENTS
和
select *from products
这两句SQL语句的效率是相同的。
页面是已经可以有数据了,就是如何把页面上的table里的数据先全部取出,然后在跟数据库里的数据进行对比啊!
这部分我不知道如何写啊!
private string SetGrid()
{
string CustomerID = "101";
DataSet ds= COM.LianJing.BusinessEntityLibrary.Purchase.PurchaseReportManagement.GetPuchasePlanList(CustomerID);
DataTable dataTable = ds.Tables[0];
System.Text.StringBuilder html = new System.Text.StringBuilder(); foreach (DataRow dataRow in dataTable.Rows)
{
html.Append( "<tr>");
html.Append( "<td noWrap align='left'><input type='checkbox'></td>");
html.Append( "<td style='DISPLAY: none' noWrap align='left'></td>");
html.Append( "<td style='DISPLAY: none' noWrap align='left'>"+dataRow["productid"]+"</td>");
html.Append( "<td style='DISPLAY: none' noWrap align='left'></td>");
html.Append( "<td style='DISPLAY: none' noWrap align='left'></td>");
html.Append( "<td>"+dataRow["productclassname"].ToString()+"</td>");
html.Append( "<td>"+dataRow["productbrand"].ToString()+"</td>");
html.Append( "<td>"+dataRow["productspec"].ToString()+"</td>");
html.Append( "<td>"+dataRow["productpack"].ToString()+"</td>");
html.Append( "<td align=center>"+dataRow["PackUnit"].ToString()+"</td>");
html.Append( "<td noWrap align=right><input id='Quantity1' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity1"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity2' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity2"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity3' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity3"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity4' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity4"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity5' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity5"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity6' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity6"].ToString()+"'></td>");
html.Append( "<td noWrap align=right><input id='Quantity7' class='tablemoneyinput' type='text' size='8' value='"+dataRow["Quantity7"].ToString()+"'></td>");
html.Append( "<td style='DISPLAY: none' noWrap align='left'></td>");
html.Append( "</tr>\t\n");
}
return html.ToString();
}
这是我读出数据库后,显示在页面上的表格的代码,
现在的问题是就是保存的时候不知道该如何写啊!