【问题标题】:No mapping exists from object type System.Windows.Forms.RichTextBox to a known managed provider native type.'不存在从对象类型 System.Windows.Forms.RichTextBox 到已知托管提供程序本机类型的映射。
【发布时间】:2019-07-02 17:59:16
【问题描述】:

我使用富文本框收集备注但没有保存在数据库中

这里是代码

            con.Open();
            SqlCommand cmd = new SqlCommand(@"insert into Student_Records(FirstName,LastName,ContactNumber,DOB,TemporaryAddress,PermanentAddress,FatherName,Fathersoccupation,ContactNumberF,MotherName,Mothersoccupation,ContactNumberM,Remarks) values(@firstname,@lastname,@contactnumber,@dob,@temporaryaddress,@permanentaddress,@fathername,@fatheroccupation,@contactnumberf,@mothername,@motheroccupation,@contactnumberm,@remarks)", con);
            cmd.Parameters.AddWithValue("@firstname", txtFname.Text);
            cmd.Parameters.AddWithValue("@lastname", txtlastN.Text);
            cmd.Parameters.AddWithValue("@contactnumber", txtCN.Text);
            cmd.Parameters.AddWithValue("@dob", dtdob.Value);
            cmd.Parameters.AddWithValue("@temporaryaddress", txtTaddress.Text);
            cmd.Parameters.AddWithValue("@permanentaddress", txtPaddress.Text);
            cmd.Parameters.AddWithValue("@fathername", txtFname.Text);
            cmd.Parameters.AddWithValue("@fatheroccupation", txtFoccupation.Text);
            cmd.Parameters.AddWithValue("@contactnumberf", txtFcn.Text);
            cmd.Parameters.AddWithValue("@mothername", txtMname.Text);
            cmd.Parameters.AddWithValue("@motheroccoupation", txtMoccupation.Text);
            cmd.Parameters.AddWithValue("@contactnumberm", txtMcn);
            cmd.Parameters.AddWithValue("@remarks", rtremarks.Rtf);
            cmd.ExecuteNonQuery();
            con.Close();

【问题讨论】:

  • txtMcn 是什么?
  • @FrankerZ Rtfstring 类型,这行应该可以正常工作

标签: c# .net winforms


【解决方案1】:

在这一行

cmd.Parameters.AddWithValue("@contactnumberm", txtMcn);

您传递的是 TextBox 本身,而不是其 Text 属性。

话虽如此,但这会产生稍微不同的错误。正如您在other question 关于这段代码中所指出的,请在收到错误时逐字发布代码和错误,否则您可能无法获得有用的答案。 (要么是那个,要么你命名txtMcn不一致!)

【讨论】:

    猜你喜欢
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多