Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Mac电脑上不显示错误信息,但在windows上工作正常_C#_Sql_Asp.net - Fatal编程技术网

C# 在Mac电脑上不显示错误信息,但在windows上工作正常

C# 在Mac电脑上不显示错误信息,但在windows上工作正常,c#,sql,asp.net,C#,Sql,Asp.net,更新:所有功能现在都正常工作。它正在执行所有必要的验证,但alertMessage(例如:ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“alertMessage”,“警报('SSN已存在,记录已更新。!'),true);)未显示在屏幕上。 它在windows上运行良好,但在Mac上无法显示 protected void BtnBtnInsert_Click(object sender, System.EventArgs

更新:所有功能现在都正常工作。它正在执行所有必要的验证,但alertMessage(例如:ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“alertMessage”,“警报('SSN已存在,记录已更新。!'),true);)未显示在屏幕上。 它在windows上运行良好,但在Mac上无法显示

protected void BtnBtnInsert_Click(object sender, System.EventArgs e)
{
    MySqlCommand cmd;
    string str;

    MySqlConnection con = new MySqlConnection(ConString);

    int Status = 0;
    con.Open();

    String UpdateQuery;
    String SSN;

    SSN = TxtBxSSSN.Text.ToString().Trim();

    if (CheckValidSSNBeforeUpdate(SSN) == "1")
    {
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('SSN already exists, record is updated.!')", true);
    }
    else
    {
        InsertNewEmployee();  
    }

    con.Close();
} 

public void InsertNewEmployee()
{
    String SSN, SFName, MName, LName, DOB, Address;

    SSN = TxtBxSSSN.Text.ToString().Trim();
    SFName = lblSFanme.Text.ToString().Trim();
    MName = lblMName.Text.ToString().Trim();
    LName = lblLName.Text.ToString().Trim();
    DOB = lblDOB.Text.ToString().Trim();
    Address = lblAddress.Text.ToString().Trim();

    String SSN1 = new String(SSN.Where(x => Char.IsDigit(x)).ToArray());

    String Tmpe = "SSN : " + SSN + " , SFName : " + SFName + " , MName : " + MName + " , LName : " + LName + " , DOB : " + DOB + " , Address : " + Address;

    if (SSN.Length == 0 || SFName.Length == 0 || MName.Length == 0 || LName.Length == 0 || DOB.Length == 0 || Address.Length == 0)
    {
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter values in all the fields. All fields are mandatory')", true);
    }
    else
    {
        if (SSN1.Length != 9)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid SSN, It must be of 9 digits')", true);
        }
        else
        {
            InsertNewEmployeeRecord();
        }
    }
}

public void InsertNewEmployeeRecord()
{
    String SSN, SFName, MName, LName, DOB, Address;

    SSN = TxtBxSSSN.Text.ToString().Trim();
    SFName = lblSFanme.Text.ToString().Trim();
    MName = lblMName.Text.ToString().Trim();
    LName = lblLName.Text.ToString().Trim();
    DOB = lblDOB.Text.ToString().Trim();
    Address = lblAddress.Text.ToString().Trim();

    MySqlCommand cmd;
    string str;

    MySqlConnection con = new MySqlConnection(ConString);

    int Status = 0;
    con.Open();

    String InsertQuery;

    InsertQuery = "Insert Into Employee VALUES ('"+SSN+ "','"+DOB+"','"+SFName+"','"+MName+"','"+LName+"','"+Address+"')";

    cmd = new MySqlCommand(InsertQuery, con);
    cmd.ExecuteNonQuery();

    con.Close();

    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record inserted successfully.!')", true);
}

在“InsertNewEmployeeRecord”方法中,您具有以下内容:

String UpdateQuery;

InsertQuery = "Insert Into Employee VALUES ('"+SSN+ "','"+DOB+"','"+SFName+"','"+MName+"','"+LName+"','"+Address+"')";

cmd = new MySqlCommand(UpdateQuery, con);
您要声明UpdateQuery,然后将值指定给InsertQuery,然后执行UpdateQuery,该值为null

因此,您需要使用:

 cmd = new MySqlCommand(InsertQuery, con);

执行此操作:从insert statemet中删除
“+SSN+”,
,然后运行代码。如果它向您发送错误消息,则表示它正在按编码方式工作。请在
InsertNewEmployeeRecord
中放置断点。你到了吗?@antoniovenerosoconteras它不发送错误消息。最小意外原则-当代码实际插入一行(根本不更新)时,你不应该称它为
UpdateQuery
。。。。。这对于以后查看代码的任何人来说都是很容易混淆的…另外:-您不应该将SQL语句连接在一起-使用参数化查询来避免SQL注入-签出谢谢插入命令正在工作。但它没有显示任何警报