protected void Button1_Click(object sender, EventArgs e)
{
string id = ((Button)sender).ID;//获取但前按钮的id
string conn = "Data Source=localhost;Initial Catalog=Data;Persist Security Info=true;User ID=sa;Password=123;";
string selectstr = "SELECT*FROM VoteCount";
SqlConnection sql = new SqlConnection(conn);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand com = new SqlCommand(selectstr, sql);
sda.SelectCommand = com;
SqlCommandBuilder objcmdBuilder = new SqlCommandBuilder(sda);//
sda.UpdateCommand = objcmdBuilder.GetUpdateCommand();
sda.InsertCommand = objcmdBuilder.GetInsertCommand();
sda.DeleteCommand = objcmdBuilder.GetDeleteCommand();
DataSet ds = new DataSet();
sql.Open();//打开数据库链接
sda.Fill(ds,"VoteCount"); DataTable dt = ds.Tables["VoteCount"];
foreach(DataRow temp in dt.Rows)
{
if (temp["ButtonLink"].ToString() ==id) Response.Write("get it");
}
}好像不能截图,麻烦:Data表中VoteCount表是这样的
ID Count ButtonLink (type:int int char(10))
1 0 Button1
老是if里面判断bool为false,输不出get it(怎么回事啊,好郁闷啊,好像有一次正确输出了,可以后怎么也输不出了,无论我吧那ButtonLink类型换成text还是varchar,都不行啊,怎么回事啊,啊啊啊啊啊!!!)
{
string id = ((Button)sender).ID;//获取但前按钮的id
string conn = "Data Source=localhost;Initial Catalog=Data;Persist Security Info=true;User ID=sa;Password=123;";
string selectstr = "SELECT*FROM VoteCount";
SqlConnection sql = new SqlConnection(conn);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand com = new SqlCommand(selectstr, sql);
sda.SelectCommand = com;
SqlCommandBuilder objcmdBuilder = new SqlCommandBuilder(sda);//
sda.UpdateCommand = objcmdBuilder.GetUpdateCommand();
sda.InsertCommand = objcmdBuilder.GetInsertCommand();
sda.DeleteCommand = objcmdBuilder.GetDeleteCommand();
DataSet ds = new DataSet();
sql.Open();//打开数据库链接
sda.Fill(ds,"VoteCount"); DataTable dt = ds.Tables["VoteCount"];
foreach(DataRow temp in dt.Rows)
{
if (temp["ButtonLink"].ToString() ==id) Response.Write("get it");
}
}好像不能截图,麻烦:Data表中VoteCount表是这样的
ID Count ButtonLink (type:int int char(10))
1 0 Button1
老是if里面判断bool为false,输不出get it(怎么回事啊,好郁闷啊,好像有一次正确输出了,可以后怎么也输不出了,无论我吧那ButtonLink类型换成text还是varchar,都不行啊,怎么回事啊,啊啊啊啊啊!!!)
解决方案 »
- WebBrowser不能弹出对话框
- 怎么在已经打开的word中打开一个模板,而不是新建一个word窗口打开
- “BLL.School.PraxisInfro”不可访问,因为它受保护级别限制 (怎么回事呀)
- 求socket通讯发送接收文件C#事例,高人帮帮忙。。
- 如何读取编辑后的单元格的值?
- WinForm中ComboBox如何根据值(ValueMember的值)定位SelectedIndex
- C#程序运行中,从窗口一中点击按钮打开另一个窗口二?
- string 类型转textbox 未将对象引用设置到对象的实例。找高手
- 请问:如何在C#制作一个橡皮擦?
- 请问, 现在研究 windows DNA还有必要吗? 能否讲讲它的精华之处? 现在新开发系统还用此模式吗 ?
- 网页游戏开发都需要哪些技术??
- linkLabel的问题
这个id是多少?
temp["ButtonLink"].ToString() 这个又是多少?
你断点调试下.是否有空格现象?
加上Trim();
if (temp["ButtonLink"].ToString().Trim() ==id) Response.Write("get it");
断点下,看temp["ButtonLink"].ToString().Trim() 和id值为多少
为true的时候才输出的