Insert into (mysql db)
hvorfor virker det her ikke?using System.Data.Odbc;
public partial class Support : System.Web.UI.Page
{
protected void BtnSubmit_Click(object sender, EventArgs e)
{
try
{
string myInsertQuery = "INSERT INTO Support (Name, EmailAddress, Header, Question, IPAddress) VALUES (?name, ?EmailAddress, ?Header, ?Question, ?IPAddress)";
// string myInsertQuery = "INSERT INTO Orders (Name, EmailAddress, Header, Question, IPAddress) Values(?name, ?Email, ?Header, ?Question, ?IPAddress)";
OdbcConnection myConnection = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=mysql.keep-gaming.com;Port=3306;Database=hidden;User=hidden;Password=hidden;Option=3;");
OdbcCommand myCommand = new OdbcCommand(myInsertQuery, myConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add("?Name", OdbcType.VarChar, 25);
myCommand.Parameters.Add("?EmailAddress", OdbcType.VarChar, 50);
myCommand.Parameters.Add("?Header", OdbcType.VarChar, 50);
myCommand.Parameters.Add("?Question", OdbcType.VarChar, 255);
myCommand.Parameters.Add("?IPAddress", OdbcType.VarChar, 15);
myCommand.Parameters["?Name"].Value = TxtName.Text;
myCommand.Parameters["?EmailAddress"].Value = TxtEmail.Text;
myCommand.Parameters["?Header"].Value = TxtHeader.Text;
myCommand.Parameters["?Question"].Value = TxtQuestion.Text;
myCommand.Parameters["?IPAddress"].Value = Request.UserHostAddress.ToString();
myCommand.Connection.Open();
Label5.Text = "It worked";
}
catch (OdbcException ex)
{
Label lbl2 = new Label();
string errorMessages = "";
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages += "<br><br>Index #" + i + "<br>" +
"Message: " + ex.Errors[i].Message + " " +
"NativeError: " + ex.Errors[i].NativeError.ToString() + " " +
"Source: " + ex.Errors[i].Source + " " +
"SQL: " + ex.Errors[i].SQLState + " ";
}
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(errorMessages);
lbl2.Text = (errorMessages) + "<br>An exception occurred. Please contact your system administrator.";
Page.Controls.Add(lbl2);
Label5.Text = "Not good";
}
}
Den siger at det virker men der insaetter intet i min database (er begynder).