0

High Im unsure how to add insert data to mysql using odbc?

I have a table called User and I would like to add generic details to it, Name, location etc etc

  {
      string = textbox1.text("Name");

      OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=root; Password=;");
      cn.Open();
OdbcCommand cmd = new OdbcCommand("INSERT INTO User (Name)");

      cmd.Parameters.Insert(Name into @name);

    }

    }
}
0

1 Answer 1

2

I'm not quite sure what you are asking but I see a few problems with your code:

  string tbValue = textbox1.text("Name"); //added variable name

  OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=root; Password=;");
  cn.Open();
  OdbcCommand cmd = 
        new OdbcCommand("INSERT INTO User (Name) VALUES (?)"); // fixed incomplete insert statement.

  cmd.Parameters.Add(tbValue); //add the parameter to the command
  cmd.ExecuteNonQuery(); //actually run the sql

There may be other problems but give this a try for starters and let us know if you have any specific problems.

Sign up to request clarification or add additional context in comments.

2 Comments

Well, that was what I was in the middle of typing, and you beat me to it Abe!! Rep points for you.
sorry the values would be the stored string from the textbox. Not sure if it would just be insert into user (name) values (tbvalue)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.