问个简单的问题,点击按钮后查找数据库,没有查找到就弹出一个窗口??? 怎么写的??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 执行SELECT COUNT(*) FROM TB 如果返回0就弹出你需要的那个窗口还有一个方法是返回受影响的行数也行EXECUTENONQUERY这个吧,忘写了 最简单的方法:如:protected void btnSearch_Click(object sender,EventArgs e){ if(没有查到) { Response.Write("<script>alter('没有找到!');</script>"); }} 最简单的方法:如:protected void btnSearch_Click(object sender,EventArgs e){ if(没有查到) { Response.Write(" <script>alert('没有找到!'); </script>"); }}如果使用了asp.net ajax框架,那么还可以这样:protected void btnSearch_Click(object sender,EventArgs e){ if(没有查到) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdatePanel1", "alert('没有找到!')", true);} LS回答分为两派,我也搞不清楚LZ问什么了, using(SqlConnection conn=new SqlConnection("")){ string strSql="SELECT isnull(count(*),0) from table where 1="1:; SqlCommand cmd=new SqlCommand(strsql,conn); conn.Open(); SqlDataReader reader=cmd.ExecuteReader(); if(reader.Read()) { if((int)reader[0]<=0)ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('');</script>"); } } reader.Close(); conn.Close(); } private void button1_Click(object sender, EventArgs e) { string connstr = @"Data Source=.\sqlexpress;Initial Catalog=temp;Integrated Security=True"; SqlConnection connection=new SqlConnection(connstr); try { string sql = "select count(*) from A"; SqlCommand command = new SqlCommand(sql,connection); connection.Open(); int result = (int)command.ExecuteScalar(); if (result > 0) { //do something } else { MessageBox.Show("没查到?"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } protected void btnSearch_Click(object sender,EventArgs e) { if(没有查到) { Response.Write(" <script>window.open('');</script>"); } } using(SqlConnection conn=new SqlConnection("")) { string strSql="SELECT isnull(count(*),0) from table where 1="1:; SqlCommand cmd=new SqlCommand(strsql,conn); conn.Open(); SqlDataReader reader=cmd.ExecuteReader(); if(reader.Read()) { if((int)reader[0] <=0)ClientScript.RegisterStartupScript(this.GetType(), "message", " <script language='javascript' defer>alert(''); </script>"); } } reader.Close(); conn.Close(); }这个可以啊。 private void ConnectDd_1() { SqlConnection myCon = new SqlConnection(); myCon.ConnectionString = @"Data Source=PC2009102316FKU\NEWSQL;Initial Catalog=my_site;User ID=sa;Password=122159575"; myCon.Open(); SqlCommand myCom = new SqlCommand(); myCom.Connection = myCon; myCom.CommandText = "select * from management where Username='" + TextBox1.Text.Trim() + "' and Password='" + TextBox2.Text.Trim() + "'"; SqlDataReader sdr = myCom.ExecuteReader(); if (sdr.Read()) { sdr.Close(); myCon.Close(); Response.Redirect("management.aspx"); } else { Response.Write(" <script>window.open('密码帐号错误'); </script>"); Response.Redirect("new_index.aspx"); } }[/code]为什么只是我乱输入的东西点登陆,就相当于刷新了一下页面。。没什么窗口弹出啊??把Response.Write(" <script>window.open('密码帐号错误'); </script>");换成Response.Write(" <script>alert('没有找到!'); </script>"); 也不只是刷新 请教XPSP3到底能不能装IIS6.0? 中文分词,用哪个比较好?要收费? FreeTextBox控件 关于iframe的问题 如何判断一个textBox里输入的是数字,还是字母? SQL Server 连接失败 急,Repeater控件设计视图时报错:请检查并确保所有属性都有效? 如何防止没有登陆网站,而通过输入页面地址来浏览网页??在.net中是否有好的方法? 谁有:datagrid控件完整的例子呀! 关于生成一条特殊的SQL语句的难题! .net连接数据库时 出错 100分求一个简单的js效果
如:
protected void btnSearch_Click(object sender,EventArgs e)
{
if(没有查到)
{
Response.Write("<script>alter('没有找到!');</script>");
}}
如:
protected void btnSearch_Click(object sender,EventArgs e)
{
if(没有查到)
{
Response.Write(" <script>alert('没有找到!'); </script>");
}}
如果使用了asp.net ajax框架,那么还可以这样:protected void btnSearch_Click(object sender,EventArgs e)
{
if(没有查到)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdatePanel1", "alert('没有找到!')", true);
}
{
string strSql="SELECT isnull(count(*),0) from table where 1="1:;
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
if((int)reader[0]<=0)ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('');</script>");
}
}
reader.Close();
conn.Close();
}
{
string connstr = @"Data Source=.\sqlexpress;Initial Catalog=temp;Integrated Security=True";
SqlConnection connection=new SqlConnection(connstr);
try
{
string sql = "select count(*) from A";
SqlCommand command = new SqlCommand(sql,connection);
connection.Open();
int result = (int)command.ExecuteScalar();
if (result > 0)
{
//do something
}
else
{
MessageBox.Show("没查到?");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
{
if(没有查到)
{
Response.Write(" <script>window.open('');</script>");
} }
{
string strSql="SELECT isnull(count(*),0) from table where 1="1:;
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
if((int)reader[0] <=0)ClientScript.RegisterStartupScript(this.GetType(), "message", " <script language='javascript' defer>alert(''); </script>");
}
}
reader.Close();
conn.Close();
}
这个可以啊。
private void ConnectDd_1()
{
SqlConnection myCon = new SqlConnection();
myCon.ConnectionString =
@"Data Source=PC2009102316FKU\NEWSQL;Initial Catalog=my_site;User ID=sa;Password=122159575";
myCon.Open();
SqlCommand myCom = new SqlCommand();
myCom.Connection = myCon;
myCom.CommandText =
"select * from management where Username='" + TextBox1.Text.Trim() + "' and Password='" + TextBox2.Text.Trim() + "'";
SqlDataReader sdr = myCom.ExecuteReader();
if (sdr.Read())
{
sdr.Close();
myCon.Close();
Response.Redirect("management.aspx");
}
else
{
Response.Write(" <script>window.open('密码帐号错误'); </script>");
Response.Redirect("new_index.aspx");
}
}
[/code]为什么只是我乱输入的东西点登陆,就相当于刷新了一下页面。。没什么窗口弹出啊??把Response.Write(" <script>window.open('密码帐号错误'); </script>");换成Response.Write(" <script>alert('没有找到!'); </script>"); 也不只是刷新