我点击按钮想检测数据库中是否有这字段的存在,code改怎么写,如果有提示不能取了,没有则提示可以用这名字!?
麻烦赐教下!!
麻烦赐教下!!
解决方案 »
- ASP.NET里面写事件函数时有智能提示吗?
- 如何取消用户控件的缓存
- 实现一个像google样式的模糊查询并动态显示在div 上
- 为什么我的IIS可以解析html而不能解析Aspx
- 关于VS设计器死机的问题
- 怎样使用asp.net向asp页面进行传值!急,在线等待
- 请问怎样实现这样的日历显示?
- 我的visual studio.net 无法创建asp.net web应用程序
- 有没有办法在datagrid中形成的超连接变为点开即调用outlook发送邮件啊
- 从孟老那COPY段程序出错
- unload事件中returnValue的值不能被父窗口获取
- 用vs2005创建的比较简单的程序放在1.1版本的服务器不能运行
SqlCommand cmd = null;
DataSet ds = new DataSet();
string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx";
string strSQL = "SELECT 1 from 表 where 字段= 'aa'"
try
{
conn = new SqlConnection(strConnectionString);
conn.Open();
cmd = new SqlCommand(strSQL,conn);
if (cmd.ExecuteScalar() == null)
{
//不存在
}else
{
//存在.
}
}
catch(System.Exception e)
{
this.Text1.Text = "错误"+e.Message;
}
finally
{
if(conn!=null)
conn.Dispose();
if(cmd!=null)
cmd.Dispose();
}
你是用一个文本框试的是吧,显示错误的信息?那如果说我已经设置了一个按钮的话,那怎么写呢?
谢谢你们啊.
: this.Text1.Text = "错误"+e.Message;
改为:
Response.Write("<script language=javascript>alert('"+"错误"+e.Message;+"');</script>");就OK了,试试
catch(System.Exception e)就是这个..
ex名字随取的,刚才那个错误是因为前面已经有定义为E的了
string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx";
这样写 看看
string strConnectionString = "server=.;uid=sa;pwd=;database=数据库"