protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
string a1 = DropDownList1.SelectedItem.Value.ToString(); string sql = "select PowerID from DEPARTMENT where Department='"+a1+"'";
DataTable dt = new DataTable();
dt = conn.GetDataTable(sql);
if (dt.Rows.Count!=0)
{
TextBox1.Text = dt.Rows[0][0].ToString();
}
else { Response.Write("<script>alert('插入失败!')</script>"); } }错误 5 “System.Data.SqlClient.SqlConnection”不包含“GetDataTable”的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlConnection”的第一个参数的扩展方法“GetDataTable”(是否缺少 using 指令或程序集引用?)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
string a1 = DropDownList1.SelectedItem.Value.ToString(); string sql = "select PowerID from DEPARTMENT where Department='"+a1+"'";
DataTable dt = new DataTable();
dt = conn.GetDataTable(sql);
if (dt.Rows.Count!=0)
{
TextBox1.Text = dt.Rows[0][0].ToString();
}
else { Response.Write("<script>alert('插入失败!')</script>"); } }错误 5 “System.Data.SqlClient.SqlConnection”不包含“GetDataTable”的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlConnection”的第一个参数的扩展方法“GetDataTable”(是否缺少 using 指令或程序集引用?)
解决方案 »
- DataControlRowState 枚举里面的Selected是什么意思啊
- 谁有远程教育软件源码吗?
- 数据查询问题
- cookie跨页提交小问题
- ASP.NET (C#)的.cs文件出现乱码
- 50分^^^^^^^^^^^^^^^^^^^^^^^^^^【关于DropDownList的取值问题】~~~~~~~~~~~~`~~~~~~UP有分
- 上传的图片用什么路径?
- ConfigurationSettings.AppSettings["jsConnString"]在同一个项目的两个不同页面Page_load中引用,一个页面引用成功,另一个失败!奇怪啊!
- 请问谁知道母板内控件回调处理过程
- visual c#command line complier已停止工作
- (紧急)vs2010 加载dll,运行时报错,任何DLL都一样
- sql server建立连接时出现与网络相关的或特定于实例的错误
{
string a1 = DropDownList1.SelectedItem.Value.ToString();
string sql = "select PowerID from DEPARTMENT where Department='" + a1 + "'";
DataTable dt = new DataTable();
dt = ReturnDataTable(sql);
if (dt.Rows.Count != 0)
{
TextBox1.Text = dt.Rows[0][0].ToString();
}
else { Response.Write("<script>alert('插入失败!')</script>"); }
}
public static DataTable ReturnDataTable(string cmdtext)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString;
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand(cmdtext, cn);
cmd.CommandType = CommandType.Text; ;
SqlDataReader dr = null;
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
return dt;
}
那我要是想达到
DROPDOWNLIST 选择 DepartmentN
TEXTBOX 获取 PowerID 该如何是好?
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
string a1 = DropDownList1.SelectedItem.Value.ToString(); string sql = "select PowerID from DEPARTMENT where Department='"+a1+"'";
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds.Tables[0].Rows.Count!=0)
{
TextBox1.Text =ds.Tables[0].Rows[0][0].ToString();
} }