[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

System.Web.UI.HtmlControls.HtmlInputText

I have the following ASP.NET contact page.
The backend is MySql.

When I click submit and look at the data in MySql, it's not what I entered.
Here is what I get:

name: System.Web.UI.HtmlControls.HtmlInputText
email: System.Web.UI.HtmlControls.HtmlInputText
message: System.Web.UI.HtmlControls.HtmlInputText

Please help
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

public partial class contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void image_Click(object sender, EventArgs e)
    {
        MySqlConnection connection = new MySqlConnection("Network Address=localhost;" +
                                                "Initial Catalog='fabrics';" +
                                                "Persist Security Info=no;" +
                                                "User Name='root';" +
                                                "Password='oap'");


        string cmdText = "INSERT INTO tblProducts(name ,email ,message)";
        cmdText += "VALUES(?name ,?email ,?message);";

        MySqlCommand cmd = new MySqlCommand(cmdText, connection);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value = name.ToString();

        cmd.Parameters.Add("?email", MySqlDbType.VarChar).Value = name.ToString();

        cmd.Parameters.Add("?message", MySqlDbType.VarChar).Value = name.ToString();

        connection.Open();
        try
        {

            int result = cmd.ExecuteNonQuery();

            lblError.Text = "Data Saved";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
}

Open in new window

0
Isaac
Asked:
Isaac
1 Solution
 
roxviperCommented:
Hi,

try name.Value instead
0
 
raaziqCommented:
u might need to specify size of the varchar while adding the parameters..

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now