小编Sem*_*ian的帖子

对象引用未设置为对象的实例.(C#Web应用程序)

请帮助我......从最近两天开始,我面临这个问题

我的Connection类

public class Connection
{
    SqlConnection conn;
    SqlCommand cmd;

    public void connclose()
    {
        conn.Close();
    }

    public Connection()
    {
        SqlConnection conn = new SqlConnection(@"server=ADMIN-PC;database=sample;Integrated security=true");
        SqlCommand cmd = null;
    }

    public void nonquery(string qry)
    {
        conn.Open();
        cmd = new SqlCommand(qry, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的课

public class Master
{
    Connection conn = new Connection();

    public void insert(string name, string place, string company, string post)
    {
        string qry = "insert into company values('" + name + "','" + place + …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
93
查看次数

名称"数据"在当前上下文中不存在

我正在尝试在类中生成try catch方法,但我正面临这个错误消息,请帮我解决这个问题.我的班级是

public string Countryadd(string country, string id)
{

     try
     {
         string data="0";
         string qry1 = "select Country from Country where Country='" + country + "'";//Checking weather txtcountry(Country Name) value is already exixst or not. If exist return 1 and not exists go to else condition
         SqlDataReader dr = conn.query(qry1);
         if (dr.Read())
         {
             return data = "1";
         }
         else//If Country Name Not Exists
         {
             string qry = "insert into Country values('" + id + "','" + country + "')";//Insertin data …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
1383
查看次数

标签 统计

c# ×2