NullReferenceException错误评价这个

NullReferenceException错误评价这个

本文介绍了System.NullReferenceException错误评价这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好家伙

此消息显示,我不知道如何处理

这里是代码

Hello guy
this message shows up and i don't know what to do with
here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            conn.Open();
            string checkuser = "select count (*) from UsersData where UserName= '" + UserName.Text + "'";
            SqlCommand com = new SqlCommand(checkuser, conn);
            int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
            if (temp == 1)
            {
                Response.Write("User Already Exists");
            }
            conn.Close();
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        try
        {
            Guid newGUDI = Guid.NewGuid();

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["UsersConnectionString"].ConnectionString);
            conn.Open(); //line 35?
            string insertQuery = "insert into UsersData (ID, UserName, Password, CellPhone, DPT) values (@ID ,@Uname ,@Pass ,@Cell ,@DPT)";
            SqlCommand com = new SqlCommand(insertQuery, conn);
            com.Parameters.AddWithValue("@ID", newGUDI.ToString());
            com.Parameters.AddWithValue("@Uname", UserName.Text);
            com.Parameters.AddWithValue("@Pass", Password.Text);
            com.Parameters.AddWithValue("@DPT", DPT.SelectedItem.Text);

            com.ExecuteNonQuery();
            Response.Redirect("UsersManger.aspx");
            Response.Write("Registration SUCESSFULL");

            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.ToString());
        }
    }
    protected void DPT_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}



谢谢。


thanks.

推荐答案




这篇关于System.NullReferenceException错误评价这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 09:32