超级菜鸟问:C#+Oracle开发Webs,如何使用datagrid显示数据。

lanting918 2004-04-24 05:30:46
超级菜鸟问:C#+Oracle开发Webs,如何使用datagrid显示数据
前台和后台,前台显示新闻,通过后台修改。如何利用组件让datagrid 显示我数据库中的数据??因为用的是oracle(别人要求的,我只会建表),所以几乎没有什么资料。新手,快要疯了。谢谢!!

请详细给出具体步骤,包括数据库连接和打开,数据集填充等。
数据库中的表字段为:orderID(编号);
Title(新闻标题);
content(内容);
addtime(修改时间);
要求显示出以上内容,并有编辑(修改)和删除的功能。

谢谢大家!!!我弄了很久了,做不出来,疯了。大家帮帮我啊!!!
...全文
45 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanting918 2004-04-25
  • 打赏
  • 举报
回复
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.OracleClient.OracleConnection oracleConnection1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lbRecordCount;
protected System.Web.UI.WebControls.Label lbPageCount;
protected System.Web.UI.WebControls.Label lbCurrentPage;
protected System.Web.UI.WebControls.LinkButton toFirst;
protected System.Web.UI.WebControls.LinkButton prePage;
protected System.Web.UI.WebControls.LinkButton nextPage;
protected System.Web.UI.WebControls.LinkButton toEnd;
protected System.Data.DataView DataViewTitle;
protected System.Data.OracleClient.OracleCommand oracleCommand1;
protected System.Data.OracleClient.OracleCommand oracleSelectCommand1;
protected System.Data.OracleClient.OracleCommand oracleInsertCommand1;
protected System.Data.OracleClient.OracleCommand oracleUpdateCommand1;
protected System.Data.OracleClient.OracleCommand oracleDeleteCommand1;
protected System.Data.OracleClient.OracleDataAdapter da;
protected System.Web.UI.WebControls.Label Label2;
lanting918 2004-04-25
  • 打赏
  • 举报
回复

News.aspx中代码:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 96px" runat="server"
Width="864px" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White"
CellPadding="4" AutoGenerateColumns="False" DataKeyField="ORDERID" DataMember="T_WEBS_NEWS"
OnEditCommand="DataGrid1_Edit" OnCancelCommand="DataGrid1_Cancel" OnUpdateCommand="DataGrid1_Updata"
OnDeleteCommand="DataGrid1_Delete">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="OrderID" SortExpression="ORDERID" ReadOnly="True" HeaderText="新闻编号"></asp:BoundColumn>
<asp:BoundColumn DataField="Title" HeaderText="标题"></asp:BoundColumn>
<asp:BoundColumn DataField="content" HeaderText="内容"></asp:BoundColumn>
<asp:BoundColumn DataField="addtime" ReadOnly="True" HeaderText="修改时间"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="修改" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" ButtonType="PushButton" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>

News.aspx.cs中代码:
private void Page_Load(object sender, System.EventArgs e)
{
BindGrid();
// 在此处放置用户代码以初始化页面
}
//数据绑定
public void BindGrid()
{
OracleConnection conn=new OracleConnection();
conn.ConnectionString="user id=scott;password=tiger;data source=bossat";
conn.Open();

string sql="select * from T_Webs_News ";
DataSet ds=new DataSet();
OracleDataAdapter da=new OracleDataAdapter(sql,conn);
da.Fill(ds,"title");

DataViewTitle=ds.Tables["title"].DefaultView;
DataViewTitle.Sort="OrderId desc";

DataGrid1.DataSource=DataViewTitle;
DataGrid1.DataBind();
conn.Close();
}
//数据编辑
public void DataGrid1_Edit(object sender, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
//取消操作
public void DataGrid1_Cancel(object sender, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
BindGrid();
}
//更新数据
public void DataGrid1_Updata(object sender, DataGridCommandEventArgs e)
{ //怎么写??有错误。
OracleConnection conn=new OracleConnection();
conn.ConnectionString="user id=scott;password=tiger;data source=bossat";
conn.Open();

string UpdataCmd = "Updata T_webs_News Set Title = @Title Where OrderID = @OrderID";
da = new OracleCommand(UpdataCmd,oracleConnection1);

BindGrid();
conn.Close();
}
public void DataGrid1_Delete(object sender, DataGridCommandEventArgs e)
{

//怎么写???

DataGrid1.EditItemIndex = -1;
BindGrid();
}
}
}
lanting918 2004-04-24
  • 打赏
  • 举报
回复
忘记说了,我用的是下载的oracle专用的数据控件。不能直接用控件吗?
然后连接,打开。数据集填充,怎么显示呢?
bitsbird 2004-04-24
  • 打赏
  • 举报
回复
你把你写的代码拿出来,帮你改改
lanting918 2004-04-24
  • 打赏
  • 举报
回复
没有人答吗??谢谢大家啊
怎么没有老师教呢??

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧