string str="select * from Table ";
con.Open();
SqlCommand cmd =new SqlCommand(str,con);
DataGrid1.DataSource=cmd.ExecuteReader();
DataGrid1.DataBind();
con.Close();
con.Open();
SqlCommand cmd =new SqlCommand(str,con);
DataGrid1.DataSource=cmd.ExecuteReader();
DataGrid1.DataBind();
con.Close();
解决方案 »
- 如何设置子线程可以随着主线程的结束而结束?
- [求助]动态绑定lookupedit的数据源
- 实现服务,双工通信,WCF学习
- 超级难度 《DataGridView问题:如何在DataGridView中添加一个合计行》,高手请进
- 急需求解的简单问题
- 启动了一个程序,如何得到它的进程PID呢?
- 发布免费软件:Contact.Net V1.0 --个人关系管理,欢迎使用哈! --放分
- C#2010连接数据库
- 类型“DropDownList”的控件“DropDownList1”必须放在具有 runat=server 的窗体标记内 的错误
- 请问,在写代码前,除了程序流程图,还有什么更好的办法表达算法
- 开发.net下商品软件,诚寻技术合作者,有志创业者请进
- 透明按钮?
SqlConnection con=new SqlConnection("server=zhangzs;database=test;uid=sa;pwd=");
string str="select * from Table ";
con.Open();
SqlCommand cmd =new SqlCommand(str,con);
DataGrid1.DataSource=cmd.ExecuteReader();
DataGrid1.DataBind();
con.Close();
public DataSet staff(string xueli)
{SqlDataAdapter MyAdapter= new SqlDataAdapter();// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["test"]); //test是web.config下设置的连接串
MyAdapter.SelectCommand = new SqlCommand("p_staff", myConnection);// Mark the Command as a SPROC
MyAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;SqlParameter parameterxueli = new SqlParameter("@xueli", SqlDbType.VarChar, 6);
parameterxueli.Value =xueli;
MyAdapter.SelectCommand.Parameters.Add(parameterxueli);
// Open the database connection and execute the command
DataSet ds=new DataSet();
myConnection.Open();
try
{
MyAdapter.Fill(ds);
return ds;
}
finally
{
myConnection.Close();
}
}//end
aspx下按钮click事件:
private void Btn_check_Click(object sender, System.EventArgs e)
{
DataGrid1.CurrentPageIndex=0;
LOVECsharp.p_staff myErp=new LOVECsharp.p_staff(); // LOVECsharp为项目名称
DataSet ds=myErp.staff(Ddl1.SelectedItem.Text.ToString());
DataView source = ds.Tables[0].DefaultView;
source.Sort=sortfield;
DataGrid1.DataSource=source;
DataGrid1.DataBind();
}
//连接数据库
string str = "user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30";
SqlConnection conn = new SqlConnection(str);
//付给dataset控件
string select = "select * from xsxx";
DataSet ds = new DataSet();
SqlDataAdapter cmm = new SqlDataAdapter(select,conn);
cmm.Fill(ds,"xsxx");
//绑定DataGrid
DataGrid1.DataSource = ds.Tables["xsxx"].DefaultView;
DataGrid1.DataBind();2。
//连接数据库
string str = "user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30";
SqlConnection conn = new SqlConnection(str);
//执行command
string select = "select * from xsxx";
SqlCommand cmd= new SqlCommand(select,conn);
cmd.Connection.Open();
//付给SqlDataReader
SqlDataReader myReader;
myReader = cmd.ExecuteReader();
3。
//连接数据库方法
//在web.config文件中加入下列代码
<appSettings>
<add key="contodata" value="user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30"/>
</appSettings>
//连接数据库,并且使用名字空间 using System.Configuration;
string strconn = ConfigurationSettings.AppSettings["contodata"];
SqlConnection conn = new SqlConnection(strconn);
我编译时报错没有DataBind()的方法。
多谢各位了!
winform下没有,但是有DataBindings 属性和 SetDataBinding 方法