dim conn as SqlConnection
dim objDa as SqlDataAdapter
dim dataSet as DataSet =new DataSet()conn.Open()
objDa=new SqlDataAdapter(strSql,conn)
objDa.Fill(dataSet,"表名")drplist01.DataSource=dataSet.Tables("表名")
drplist01.DataBind()
dim objDa as SqlDataAdapter
dim dataSet as DataSet =new DataSet()conn.Open()
objDa=new SqlDataAdapter(strSql,conn)
objDa.Fill(dataSet,"表名")drplist01.DataSource=dataSet.Tables("表名")
drplist01.DataBind()
解决方案 »
- 有两台服务器,不在同一局域网 怎么将文件实时同步
- 急~上传图片到服务器时报413错误
- 填充无效,无法被移除。
- IIs里运行,为什提示找不到存储过程(可以追加分的)在线等
- 问一个Jmail问题???机器上没有注册Jmail为什么使用它时不报错,,怪了??
- 没有人指点以下吗,
- 在使用了母版页的内容页中,如何在JavaScript中调用Html Input(Hidden)控件?
- 急急急,想挑台能跑.net的二手笔记本.请大家帮选择一下!
- 急救!两层模型出错,找不到namespace(附代码)
- .net 制作一个 发微信的 小例子 ?
- 关于网页过期和数据库并发的问题!?
- 高分求动态新闻发布系统的原码(C#,代码分离)
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace DataBind_BLA
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected DataBind_BLA.DataSet1 dataSet11;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.DataView dataView1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataSet11 = new DataBind_BLA.DataSet1();
this.dataView1 = new System.Data.DataView();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT id, name, pwd, ipc FROM zcw.zcw";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO zcw.zcw(name, pwd, ipc) VALUES (@name, @pwd, @ipc); SELECT id, name, " +
"pwd, ipc FROM zcw.zcw WHERE (id = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.NVarChar, 500, "name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@pwd", System.Data.SqlDbType.NVarChar, 500, "pwd"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ipc", System.Data.SqlDbType.VarBinary, 2147483647, "ipc"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE zcw.zcw SET name = @name, pwd = @pwd, ipc = @ipc WHERE (id = @Original_id) AND (name = @Original_name OR @Original_name IS NULL AND name IS NULL) AND (pwd = @Original_pwd OR @Original_pwd IS NULL AND pwd IS NULL); SELECT id, name, pwd, ipc FROM zcw.zcw WHERE (id = @id)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.NVarChar, 500, "name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@pwd", System.Data.SqlDbType.NVarChar, 500, "pwd"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ipc", System.Data.SqlDbType.VarBinary, 2147483647, "ipc"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_name", System.Data.SqlDbType.NVarChar, 500, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "name", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_pwd", System.Data.SqlDbType.NVarChar, 500, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pwd", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.BigInt, 8, "id"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM zcw.zcw WHERE (id = @Original_id) AND (name = @Original_name OR @Orig" +
"inal_name IS NULL AND name IS NULL) AND (pwd = @Original_pwd OR @Original_pwd IS" +
" NULL AND pwd IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_name", System.Data.SqlDbType.NVarChar, 500, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "name", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_pwd", System.Data.SqlDbType.NVarChar, 500, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "pwd", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"JZIT-NIC\";packet size=4096;user id=zcw;data source=\"192.168.0.195" +
"\";persist security info=False;initial catalog=aspnet";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "zcw", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("name", "name"),
new System.Data.Common.DataColumnMapping("pwd", "pwd"),
new System.Data.Common.DataColumnMapping("ipc", "ipc")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
this.DataBinding += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit(); }
#endregion
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 40px" runat="server" Width="543px" BorderColor="#CCCCCC" BorderWidth="1px" BackColor="White" DataSource='<%# DataBinder.Eval(dataSet11, "Tables[zcw].DefaultView.[0]") %>' CellPadding="3" BorderStyle="None" DataKeyField="id" DataMember="zcw">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle>
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="id" HeaderText="id"></asp:BoundColumn>
<asp:BoundColumn DataField="name" HeaderText="name"></asp:BoundColumn>
<asp:BoundColumn DataField="pwd" HeaderText="pwd"></asp:BoundColumn>
<asp:ButtonColumn Text="选择" CommandName="Select"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:DataGrid></FONT>
</form>
</body>
</HTML>是这个吗?
dim objDa as SqlDataAdapter
dim dataSet1 as DataSet =new DataSet()conn.Open()
objDa=new SqlDataAdapter(strSql,conn)
objDa.Fill(dataSet1,"表名")drplist01.DataSource=dataSet1;
drplist01.DataBind()
_comm.Parameters.Add("@PersonId", SqlDbType.Int).Value = nPersonId; DataSet dsDATA = new DataSet();
SqlDataAdapter sdaDATA = new SqlDataAdapter();
sdaDATA.SelectCommand = _comm;
sdaDATA.Fill(dsDATA, "0");
然后在代码中读出数据后记得加上这条语句DataGrid.DataBind(),否则就是调试到后年你也调不出来
我的原代码在这。using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WebApplication2.DataSet1 dataSet11;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new WebApplication2.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "name", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("name", "name"),
new System.Data.Common.DataColumnMapping("password", "password")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO name(id, name, password) VALUES (@id, @name, @password); SELECT id, n" +
"ame, password FROM name";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.VarChar, 10, "id"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 10, "name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"EPAI-ZCW\";packet size=4096;user id=sa;data source=\"EPAI-ZCW\";pers" +
"ist security info=False;initial catalog=zcw";
this.sqlConnection1.InfoMessage += new System.Data.SqlClient.SqlInfoMessageEventHandler(this.sqlConnection1_InfoMessage);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT id, name, password FROM name";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit(); }
#endregion private void sqlConnection1_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
{
} private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
}
}
}