在这一行运行 c# 代码后,我得到了 nullrefernce 异常
var data = info.details.Split('|');
c#代码:
public studentinfo SaveData(studentinfo info)
{
bool returnBool=false;
SqlConnection con;
var data = info.details.Split('|');
var response = new studentinfo
{
ID = data[0],
Name = data[1],
Project = data[2],
Result = data[3]
};
con = new SqlConnection(ConfigurationManager.ConnectionStrings["Myproject.Properties.Settings.MyConnection"].ConnectionString);
string sqlStr = "INSERT INTO Result (ID,Name,Project,Result) values('" + data[0] + "', '" + data[1] + "', '" + data[2] + "', '" + data[3] + "')";
SqlCommand dbCommand = new SqlCommand(sqlStr, con);
try
{
con.Open();
if (dbCommand.ExecuteNonQuery() != 0)
{
returnBool = true;
}
if (!data.Equals(null))
{
returnBool = true;
}
con.Close();
}
catch
{
returnBool= false;
}
con.Close();
return response;
}
我试图实现:
if (!data.Equals(null))
{
returnBool = true;
}
但即便如此,它也会给出相同的对象引用异常,请帮我解决它。谢谢