codesmith7 mysql_CodeSmith7连接Mysql

本文档展示了如何使用C#代码从数据库连接中获取`CREATE TABLE`语句,通过`SHOW CREATE TABLE`命令,为特定表收集并保存扩展属性,重点在于数据库表结构管理和SQL操作的实践应用。
摘要由CSDN通过智能技术生成

if (schemaObject is TableSchema)

{

TableSchema tableSchema = schemaObject as TableSchema;

string commandText = string.Format(@"SHOW CREATE TABLE `{0}`.`{1}`", tableSchema.Database.Name, tableSchema.Name);

using (DbConnection connection = CreateConnection(connectionString))

{

connection.Open();

DbCommand command = connection.CreateCommand();

command.CommandText = commandText;

command.Connection = connection;

using (IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))

{

while (reader.Read())

{

string createtable = reader.GetString(1);

extendedProperties.Add(new ExtendedProperty("CS_CreateTableScript", createtable, DbType.String));

}

if (!reader.IsClosed)

reader.Close();

}

if (connection.State != ConnectionState.Closed)

connection.Close();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值