我原来用的是mysql5.5.28版本,下面的函数能够正常调用,现在我把数据库改为5.6.12免安装版,出现了“指定的转换无效”的错误,试了几种类型也都不行,问下该如何获取该数据,谢谢!函数内容介绍:插入一行用户信息,userid为自增类型数据,插入后通过LAST_INSERT_ID()获取刚插入的值并返回
public bool InsertRowUserInfo(DataRow rowUserInfo, out UInt32 userIdxx)
{
DataTable tbId = new DataTable();
userIdxx = 0; try
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandText = "InsertTbUserInfo";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("?p_userid", rowUserInfo["USER_ID"]);
command.Parameters.AddWithValue("?p_username", rowUserInfo["USER_NAME"]);
command.Parameters.AddWithValue("?p_phone", rowUserInfo["PHONE"]);
command.Parameters.AddWithValue("?p_address", rowUserInfo["ADDRESS"]);
command.Parameters.AddWithValue("?p_usermemo", rowUserInfo["USER_MEMO"]);
command.Parameters.AddWithValue("?p_villageid", rowUserInfo["VILLAGE_ID"]);
command.ExecuteNonQuery(); //通过SELECT LAST_INSERT_ID(); 获取最近插入的自增型数据的值。
command.CommandText = "SelectLastInsertID"; //即LAST_INSERT_ID()
command.ExecuteNonQuery(); MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = command;
tbId.Clear();
adapter.Fill(tbId);
connection.Close();
userIdxx = (UInt32)(long)tbId.Rows[0][0];
command.Dispose();
connection.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
return true;
}
public bool InsertRowUserInfo(DataRow rowUserInfo, out UInt32 userIdxx)
{
DataTable tbId = new DataTable();
userIdxx = 0; try
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandText = "InsertTbUserInfo";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("?p_userid", rowUserInfo["USER_ID"]);
command.Parameters.AddWithValue("?p_username", rowUserInfo["USER_NAME"]);
command.Parameters.AddWithValue("?p_phone", rowUserInfo["PHONE"]);
command.Parameters.AddWithValue("?p_address", rowUserInfo["ADDRESS"]);
command.Parameters.AddWithValue("?p_usermemo", rowUserInfo["USER_MEMO"]);
command.Parameters.AddWithValue("?p_villageid", rowUserInfo["VILLAGE_ID"]);
command.ExecuteNonQuery(); //通过SELECT LAST_INSERT_ID(); 获取最近插入的自增型数据的值。
command.CommandText = "SelectLastInsertID"; //即LAST_INSERT_ID()
command.ExecuteNonQuery(); MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = command;
tbId.Clear();
adapter.Fill(tbId);
connection.Close();
userIdxx = (UInt32)(long)tbId.Rows[0][0];
command.Dispose();
connection.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
return true;
}
解决方案 »
- 求助一个单表数据排序的sql语句写法
- 请教个问题:如何在一个表中所有字段中查询某信息?
- ERROR 1336 (0A000): Dynamic SQL is not allowed in stored function or trigger
- MYSQL怎样设置字段为不可重复?
- 哪位大哥帮忙写一下这个SQL。
- could not connect to the specified instance
- XP中如何安装哪个版本的mysql(4.0.23还是4.1.8)
- 急!!!!MYSQL大虾速进!!!!
- 如何通过SQL文件创建表?
- mysql存储emoji表情问题
- 帮忙优化个语句吧
- mysql较大数据量查询更新问题
谁来顶下贴,我好结贴,谢谢!
userIdxx = uint.Parse(tbId.Rows[0][0].ToString());