又送100分,老问题还没有解决,新问题又来了

rhs 2004-05-03 09:21:13
老问题:http://expert.csdn.net/Expert/topic/3024/3024840.xml?temp=.3193476
但我想把数据查询结果放在一个DataTable中于是把程序写成如下:
this.mTable = new System.Data.DataTable();//这儿有问题??
 conn = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OleDb.4.0; Data source = party.mdb");
conn.Open();
 string strsql = "select ID,sum(item1+item2...) as total " +
 "into tblresult from tblMark "+ "where datediff(mm,date(),dates)=0     group by ID" ;
this.da = new System.Data.OleDb.OleDbDataAdapter(strsql,this.conn);
try
{
this.da.Fill(this.mTable);//发生异常 
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"error");
this.conn.Close();
}
异常提示如下:"至少一个参数没有被指定值".哪儿问题啊,是不是mTable的问题??

新问题:
this.DataGrid1 = new DataGrid();
this.tblBook1 = new DataTable();
string mysql = "select tblbooks.bookID,tblbooks.bookName,tblborrow.BorrowDate from tblborrow ,tblbooks "+ "where tblbooks.bookID in (select bookID from tblborrow where Number ='" + Session["id"] +"')";
this.conn = new SqlConnection("server=local;database=lib;uid=sa;pwd=123");
this.da1 = new SqlDataAdapter(mysql,this.conn);
this.da1.Fill(this.tblBook1);
this.labtotal.Text = "你总共借了" + this.tblBook1.Rows.Count.ToString();
Session["moreBook"] = 5 - this.tblBook1.Rows.Count;
this.labMore.Text = "你还可以借" + Session["moreBook"].ToString()+"本";
DataView dv = new DataView(this.tblBook1);
this.DataGrid1.DataSource = dv;
this.DataGrid1.DataBind();

这是一个借书查询的,
第一个问题:查询结果记录重复.同一个记录在结果中连续出现两次.怎样修改sql语句?
第二个问题:tblBook1中有记录显示.但DataGrid1没显示结果,而且连框架都没显示.Visible属性可是true.
...全文
52 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
rhs 2004-05-03
DataGrid是ASP.net哪个.
  • 打赏
  • 举报
回复
bitsbird 2004-05-03
DataGrid dg = new DataGrid();
this.Controls.Add(dg);

dg.AutoGenerateColumns = false;

BoundColumn bc = new BoundColumn();
bc.DataField = "YourColumnName";
dg.Columns.Add(bc);
...

dg.DataSource = ...;
dg.DataBind();public DataGrid MakeGrid()
{
mygrid.CellPadding=2;
mygrid.Attributes.Add("align","center");
mygrid.CellSpacing=0;
mygrid.Width=500;
mygrid.BorderWidth=1;
mygrid.BorderColor=ColorTranslator.FromHtml("Black");
mygrid.AutoGenerateColumns=false;
mygrid.ForeColor=ColorTranslator.FromHtml("Black");
mygrid.Font.Size=9;
mygrid.Font.Name="宋体";
mygrid.AllowSorting=true;

///sort命令的事件处理器

mygrid.SortCommand += new DataGridSortCommandEventHandler(Sort_Grid);

///设置headerstyle
mygrid.HeaderStyle.BackColor=ColorTranslator.FromHtml("Gold");
mygrid.HeaderStyle.ForeColor=ColorTranslator.FromHtml("Black");
mygrid.HeaderStyle.Font.Name="宋体";
mygrid.HeaderStyle.Font.Size=9;
mygrid.HeaderStyle.Font.Bold=true;
mygrid.HeaderStyle.HorizontalAlign=HorizontalAlign.Center;
  • 打赏
  • 举报
回复
rhs 2004-05-03
TO: wangsaokui(无间道II(前传))
哦,一言惊醒梦中人.真是多谢你.
还两个问题.那个好心人帮帮忙,很急的.如谦不够分可再加啊.
  • 打赏
  • 举报
回复
wangsaokui 2004-05-03
tblbooks.bookID,tblbooks.bookName,tblborrow.BorrowDate from tblborrow ,tblbooks "+ "where tblbooks.bookID in (select bookID from tblborrow where Number ='" + Session["id"] +"')";

没有tblbooks.bookID=tblborrow.bookID
把这句加到where子句中。
  • 打赏
  • 举报
回复
rhs 2004-05-03
to: lihao9806(李昊)
这样还不行,这样只能使得结果重复两次(不再是其中结果连续重复两次).
tblbooks表结构是这样的:
bookID(主键) |bookName |
-----
tblborrow表结构如下:
BorrowDate | bookID (是外键)
  • 打赏
  • 举报
回复
lihao9806 2004-05-03
第一个问题:查询结果记录重复.同一个记录在结果中连续出现两次.怎样修改sql语句?
select distinct tblbooks.bookID,tblbooks.bookName,tblborrow.BorrowDate
from ...
where ...
  • 打赏
  • 举报
回复
相关推荐
发帖
C#
加入

10.6w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2004-05-03 09:21
社区公告

让您成为最强悍的C#开发者