有系统问题.NullReferenceException错误...请帮助

编程入门 行业动态 更新时间:2024-10-11 23:17:50
本文介绍了有系统问题.NullReferenceException错误...请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我收到的错误就像 错误:System.NullReferenceException:对象引用未设置为对象的实例。 at student._Default.clicked(Object sender,EventArgs e) 不知道为什么?我的代码有什么问题吗? 请帮忙... thnks ...

使用系统; 使用 System.Collections; 使用 System.Configuration; 使用 System.Data; 使用 System.Linq; 使用 System.Web; 使用 System.Web.Security; 使用 System.Web.UI; 使用 System.Web.UI.HtmlControls; 使用 System.Web.UI.WebControls; 使用 System.Web.UI.WebControls.WebParts; 使用 System.Xml.Linq; 使用 System.Data.SqlClient; 命名空间学生 { public partial class _Default:System.Web.UI.Page { protected void Page_Load( object sender,EventArgs e) {} 受保护 void 点击( object sender,EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ stdConnectionStrings]的ConnectionString)。 con.Open(); string user = select count(* )来自stdtable,其中std_name =' + TextBox1.Text + '; SqlCommand com = new SqlCommand(user,con); int a = Convert.ToInt32(com.ExecuteScalar()); if (a == 1 ) {回复。写( 用户已存在); } string insertQuery = 插入stdtable(std_name,roll,std_address)值(@ std_name,@ roll,@ std_address); com.Parameters.AddWithValue( @ std_name,TextBox1.Text); com.Parameters.AddWithValue( roll,TextBox2.Text); com.Parameters.AddWithValue( @ std_address,TextBox3.Text); com.ExecuteNonQuery(); Response.Redirect( stdadmin.aspx); Response.Write( registration successcescesfull ...); con.Close(); } catch (例外情况) { Response.Write( 错误: + ex.ToString()); } } } }

解决方案

ConfigurationManager.ConnectionStrings [stdConnectionStrings]。ConnectionString 检查这是否包含值。 如果你调试代码,你将能够到达抛出错误的确切行。

检查配置文件中的连接字符串名称是否正确。如果您的连接字符串名称不正确,您将收到此错误。

这是什么意思? SqlConnection con = 新的SqlConnection (ConfigurationManager.ConnectionStrings [stdConnectionStrings] .ConnectionString); con.Open ();

hi,I'm getting error like error:System.NullReferenceException: Object reference not set to an instance of an object. at student._Default.clicked(Object sender, EventArgs e) don't know why?is there anything wrong in my code? please help... thnks...

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace student { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void clicked(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stdConnectionStrings"].ConnectionString); con.Open(); string user = "select count(*)from the stdtable where std_name='" + TextBox1.Text + "'"; SqlCommand com = new SqlCommand(user, con); int a = Convert.ToInt32(com.ExecuteScalar()); if (a == 1) { Response.Write("user already exist"); } string insertQuery = "insert into stdtable (std_name,roll,std_address) values (@std_name,@roll,@std_address)"; com.Parameters.AddWithValue("@std_name", TextBox1.Text); com.Parameters.AddWithValue("roll", TextBox2.Text); com.Parameters.AddWithValue("@std_address", TextBox3.Text); com.ExecuteNonQuery(); Response.Redirect("stdadmin.aspx"); Response.Write("registration succescesfull..."); con.Close(); } catch (Exception ex) { Response.Write("error: " + ex.ToString()); } } } }

解决方案

ConfigurationManager.ConnectionStrings["stdConnectionStrings"].ConnectionString Check if this contains a value. If you debug your code you will be able to get to the exact line throwing the error.

Check if your connection string name is correct in your config file. If you have your connection string name incorrect, you will get this error.

what does it mean? SqlConnection con = new SqlConnection (ConfigurationManager.ConnectionStrings [ "stdConnectionStrings" ].ConnectionString); con.Open();

更多推荐

有系统问题.NullReferenceException错误...请帮助

本文发布于:2023-11-25 09:32:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   系统   NullReferenceException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!