如何在vb.net 10中检查表字段(mysql)的数据类型以及更改 [英] How can i check data type of table fields(mysql) in vb.net 10 as well as change
本文介绍了如何在vb.net 10中检查表字段(mysql)的数据类型以及更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vb.net 10中检查表字段(mysql)的数据类型以及更改
解决方案
以下是您需要执行的查询在.net中使用SqlConnection和SqlCommand对象
SHOW COLUMNS FROM mytable FROM mydb;
此查询将返回表格的各列及其各自的数据类型
对于changind数据类型,您可以使用Alter tbale查询
ALTER TABLE `mydb` .mytable`修改 COLUMN `mycol` TIMESTAMP ;
您可以使用DATAReader和数据连接对象从VB.net运行此查询
选择 data_type
from information_schema.columns
其中 table_schema = ' myschema'
和 table_name = ' < span class =code-string> mytable'
和 column_name = ' mycol'
替换数据库,表格,字段名称
你可以运行查询更改字段来改变我的sql类型,大小
阅读下面的mysql博客了解有关ALTER查询的更多信息
ALTER TABLE语法 [ ^ ]
进口 M ySql.Data.MySqlClient
公共 Sub DataLoad( ByVal mMySQLConnectionString 作为 字符串, ByVal pStoredProcedureString 作为 字符串)
尝试
使用 mMySqlConnection 作为 New MySqlConnection(mMySQLConnectionString)
mMySqlConnection.Open()
使用 mMySqlCommand 作为 新 MySqlCommand
使用 mMySqlCommand
.Connection = mMySqlConnection
。命令Type = CommandType.StoredProcedure
.CommandText = pStoredProcedureString
mMySqlDataReader = .ExecuteReader(CommandBehavior.SingleResult)
End 使用
对于 i 作为 整数 = 0 mMySqlDataReader.FieldCount - 1
Debug.print( CStr (mMySqlDataReader.GetFieldType(i)))
< span class =code-keyword>下一步
结束 使用
Catch exErr As 异常
MsgBox(exErr.Message)
最后
如果 不 IsNothing(mMySqlDataReader) 然后
mMySqlDataReader.Close()
mMySqlDataReader = 没什么
< span class =code-keyword>结束 如果
结束 尝试
结束 Sub
How can i check data type of table fields(mysql) in vb.net 10 as well as change
解决方案
Below is the query which you need to execute using SqlConnection and SqlCommand object in .net
SHOW COLUMNS FROM mytable FROM mydb;
This query will return columns of the table with their respective data type
For changind data type you can use Alter tbale query
ALTER TABLE `mydb`.`mytable` MODIFY COLUMN `mycol` TIMESTAMP;
You can run this query from VB.net using DATAReader and Data connection object
select data_type from information_schema.columns where table_schema = 'myschema' and table_name = 'mytable' and column_name = 'mycol'
Replace your database , table , field names
You can run query for alteration of field to change type , size in my sql
read below mysql blog to know more about ALTER query
ALTER TABLE Syntax[^]
Imports MySql.Data.MySqlClient Public Sub DataLoad(ByVal mMySQLConnectionString As String, ByVal pStoredProcedureString As String) Try Using mMySqlConnection As New MySqlConnection(mMySQLConnectionString) mMySqlConnection.Open() Using mMySqlCommand As New MySqlCommand With mMySqlCommand .Connection = mMySqlConnection .CommandType = CommandType.StoredProcedure .CommandText = pStoredProcedureString mMySqlDataReader = .ExecuteReader(CommandBehavior.SingleResult) End With For i As Integer = 0 To mMySqlDataReader.FieldCount - 1 Debug.print(CStr(mMySqlDataReader.GetFieldType(i))) Next End Using Catch exErr As Exception MsgBox(exErr.Message) Finally If Not IsNothing(mMySqlDataReader) Then mMySqlDataReader.Close() mMySqlDataReader = Nothing End If End Try End Sub
这篇关于如何在vb.net 10中检查表字段(mysql)的数据类型以及更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文