开发者

add data to sql database? Using odbc

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);

    }

    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜