public class LiknBase
{
public static SqlConnection myConnection = new SqlConnection ("packet size=4096;user id=sa;initial catalog=HuaDong;p" +"ersist security info=True;password=123");
public static DataTable SelectDataBase(string tempStrSQL)
{
DataSet ds = new DataSet();
try
{
SqlDataAdapter da = new SqlDataAdapter(tempStrSQL,myConnection);
da.Fill(ds);
}
catch(Exception ee)
{}
return ds.Tables[0];
} public static int UpdateDataBase(string tempStrSQL)
{
int intNumber=0;
try
{
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
myConnection.Open();
SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL,myConnection);
intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
myConnection.Close();
}
catch(Exception ee)
{}
return intNumber; }
}string sql="select wordbook_monnect from wordbook where wordbook_code>'110101' and wordbook_code<'331181' and Wordbook_TYPE='中华人民共和国行政区划'";
this.DropDownList5.DataSource=LiknBase.SelectDataBase(sql);
this.DropDownList5.DataBind();当我运行的时候 为什么
我的DropDownList5 现在很多条记录但是都是 " System.Data.....DefaultView"下面方法可以实现我知道...
DropDownList1.DataSource = DataSet1.Tables["Users"].DefaultView; 我现在想用字符串连接~ 所以怎么修改我方法能够实现了?
{
public static SqlConnection myConnection = new SqlConnection ("packet size=4096;user id=sa;initial catalog=HuaDong;p" +"ersist security info=True;password=123");
public static DataTable SelectDataBase(string tempStrSQL)
{
DataSet ds = new DataSet();
try
{
SqlDataAdapter da = new SqlDataAdapter(tempStrSQL,myConnection);
da.Fill(ds);
}
catch(Exception ee)
{}
return ds.Tables[0];
} public static int UpdateDataBase(string tempStrSQL)
{
int intNumber=0;
try
{
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
myConnection.Open();
SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL,myConnection);
intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
myConnection.Close();
}
catch(Exception ee)
{}
return intNumber; }
}string sql="select wordbook_monnect from wordbook where wordbook_code>'110101' and wordbook_code<'331181' and Wordbook_TYPE='中华人民共和国行政区划'";
this.DropDownList5.DataSource=LiknBase.SelectDataBase(sql);
this.DropDownList5.DataBind();当我运行的时候 为什么
我的DropDownList5 现在很多条记录但是都是 " System.Data.....DefaultView"下面方法可以实现我知道...
DropDownList1.DataSource = DataSet1.Tables["Users"].DefaultView; 我现在想用字符串连接~ 所以怎么修改我方法能够实现了?
解决方案 »
- UpdatePanel里的textbox的TextChanged事件只触发一次
- 数据库连接问题
- SQL语句有语法错误,帮我找找
- VS2005中aspx页面中不支持marquee,请问怎样在VS2005中做出marquee的效果(其中文字有超级联接)?
- 请高手帮我解决个问题?
- DataGrid表格问题
- 在.NET环境下将报表导出Excel和Word ?
- 关于Microsoft Office Web 组件
- asp.net运行一次后,源程序能删除吗?
- 如何在.CS中调用独立js文件中的某个函数值!急急急急!
- 请问在asp.net中怎么弹出一个可选路径的对话框!
- 【求助】如何实现类似word上的全选、复制、撤销、左右对齐、文本颜色格式等的文本编辑功能??
{
DataSet ds = 执行(sql);
if (ds == null || ds.Tables[0].Rows.Count==0)
return null;
DataTable dt = ds.Tables[0];
System.Type type = dt.Columns[0].DataType;
DataRow dr = dt.NewRow();
if (type.FullName.IndexOf("Int32")>0 || type.FullName.IndexOf("Byte")>0 || type.FullName.IndexOf("Int16")>0)
dr[0]=0;
else
dr[0]="";
dr[1]="请选择";
dt.Rows.InsertAt(dr,0);
return dt;
}
以上是通用方法。。自己可以改进this.DropDownList.DataSource = GetDropDownListTable(sql)
DropDownList.DataBind();
this.genreDropDownList.DataSource = ds;
this.genreDropDownList.DataTextField = "PClass_Name";//你要显示的字段
this.genreDropDownList.DataValueField = "PClass_ID";//该字段编号
this.genreDropDownList.DataBind();