";期望标识符”;.I';我正试图在ASP.NET C#上提交此表单

本文关键字:NET ASP 表单 提交 标识符 期望 quot | 更新日期: 2023-09-27 17:50:18

错误只发生在电子邮件、电话和消息中-为什么会这样?使用的数据类型为char用于nameint用于phonevarchar用于MessgaeEmail

protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection cnn = new SqlConnection();
    ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
    cnn.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "select * from ContactUs";
    cmd.Connection = cnn;
    SqlDataAdapter adp = new SqlDataAdapter();
    DataSet ds = new DataSet();
    adp.Fill(ds, "ContactUs");
    SqlCommandBuilder cb = new SqlCommandBuilder(adp);
    DataRow drow = ds.Tables["ContactUs"].NewRow();
    drow["Name"] = TextBox1.Text;         
    drow.["Email"]=TextBox2.Text;
    drow.["Phone"]=TextBox3.Text;
    drow.["Messgae"]=TextBox4.Text;
    ds.Tables["ContactUS"].Rows.Add(drow);
    adp.Update(ds,"ContactUs");
}

";期望标识符”;.I';我正试图在ASP.NET C#上提交此表单

问题:在访问/设置数据行中的值时添加点.

解决方案:访问数据行时不需要添加点.

替换此:

    drow.["Email"]=TextBox2.Text;
        ^^ //remove this
    drow.["Phone"]=TextBox3.Text;
        ^^ //remove this
    drow.["Messgae"]=TextBox4.Text;
        ^^ //remove this

有了这个:

    drow["Email"]=TextBox2.Text;
    drow["Phone"]=TextBox3.Text;
    drow["Messgae"]=TextBox4.Text;

您的列名正确吗?至少有一个拼写错误(Messgae而不是Message(。

此外,数组下标或索引器前面没有点。拆下。在CCD_ 12和CCD_。

添加此代码:

s.Tables["ContactUs"].Columns.Add("Name", typeof(string));
s.Tables["ContactUs"].Columns.Add("Email", typeof(string));
s.Tables["ContactUs"].Columns.Add("Phone", typeof(int));
s.Tables["ContactUs"].Columns.Add("Messgae", typeof(string));