本人是C#初学者,跪求各位相救~~~
已经用Navicat Lite for MySQL建好表
表中有TID和TNAME
TID是主键且自增
TNAME为varchar我想用下面这段代码插入TNAME的数据using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string connString = "server=127.0.0.1;database=mysql;uid=root;pwd=root";
MySqlConnection conn = new MySqlConnection(connString);
conn.Open();
MySqlCommand comm = new MySqlCommand("insert into uploadimage(TNAME) values(?'dfd')",conn);
comm = new MySqlCommand("select * from uploadimage", conn);
MySqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
int TID = reader.GetInt16("TID");
string TNAME = reader.GetString("TNAME");
Console.WriteLine(TID + "," + TNAME);
}
Console.WriteLine("OK...finished...");
comm.Connection.Close();
Console.ReadLine();
}
}
}
但是结果显示id没有自增,TNAME也没有写入数据库,这是为什么呢?
已经用Navicat Lite for MySQL建好表
表中有TID和TNAME
TID是主键且自增
TNAME为varchar我想用下面这段代码插入TNAME的数据using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string connString = "server=127.0.0.1;database=mysql;uid=root;pwd=root";
MySqlConnection conn = new MySqlConnection(connString);
conn.Open();
MySqlCommand comm = new MySqlCommand("insert into uploadimage(TNAME) values(?'dfd')",conn);
comm = new MySqlCommand("select * from uploadimage", conn);
MySqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
int TID = reader.GetInt16("TID");
string TNAME = reader.GetString("TNAME");
Console.WriteLine(TID + "," + TNAME);
}
Console.WriteLine("OK...finished...");
comm.Connection.Close();
Console.ReadLine();
}
}
}
但是结果显示id没有自增,TNAME也没有写入数据库,这是为什么呢?
我的也是...