什么是实例失败。我正在执行项目。但它正在给出实例失败错误 [英] What is an instance failure .i am executing the project.but it is giving the instance failure error

查看:87
本文介绍了什么是实例失败。我正在执行项目。但它正在给出实例失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Class1 obj = new Class1();
 DataSet ds1 = new DataSet();
 ds1 = obj.calldata("select * from cust_detail where cust_fname ='"+txtfname.Text+"' ");
   if (ds1.Tables[0].Rows.Count >= 1)
       {
           Response.Write("<script>alert('User name is aleready exists')</script>");
       }





CLASS1.CS





CLASS1.CS

SqlConnection con = new SqlConnection();
	public Class1()
	{
      con.ConnectionString = @"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Mydatabase.mdf;Integrated Security=True;User Instance=True";	
	}

    public DataSet calldata(string str)
    {
        SqlDataAdapter adp = new SqlDataAdapter(str, con);
        DataSet ds1 = new DataSet();
        adp.Fill(ds1);
        return ds1;
    }

推荐答案





问题是这里:

Hi,

The problem is here:
con.ConnectionString = @"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Mydatabase.mdf;Integrated Security=True;User Instance=True";



你逃避反斜杠:你写了 \\ 但是因为你添加了 @ 在你的字符串前签名,你不需要逃脱。所以,只需删除 @ 符号。

更多关于C#中的at符号(逐字字符串文字):http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71 %29.aspx [ ^ ]


You escape your backslash: you wrote \\ but because you added a @ sign before your string, you don''t need to escape. So, just remove the @ sign.
More about the at-sign in C# (verbatim string literal): http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx[^]


这篇关于什么是实例失败。我正在执行项目。但它正在给出实例失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆