在Mac上不显示错误的按摩,但在Windows上完美的工作。

更新:现在所有的功能都正常工作了。它正在做所有必要的验证,但Alertmassage(例如,它是一个很好的例子。ScriptManager.RegisterClientScriptBlock(this, this.GetType(), “alertMessage”, “alert(‘SSN already exists, record is updated.’)”, 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,而UpdateQuery是空的,所以你需要使用:

所以你需要使用。

 cmd = new MySqlCommand(InsertQuery, con);

给TA打赏
共{{data.count}}人
人已打赏
未分类

安全依赖性和已实现的登录页面

2022-9-8 11:55:37

未分类

为什么Dapper比Dapper plus快?

2022-9-8 11:55:39

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索