如何查找表格中的列数 [英] How do I find the number of columns in my table
本文介绍了如何查找表格中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到表格中的列数:表1.
我该怎么做?
Dim connStr,cmdStr As 字符串
尝试
connStr = 连接字符串有效
cmdStr = SELECT * FROM [Table1];
使用 conn 作为 新 SqlConnection(connStr)
使用 cmd As 新 SqlCommand(cmdStr,conn)
conn.Open()
使用 myreader = cmd.ExecuteReader()
如果 myreader.Read()那么
对于 每个 k 在 列
' 如何找到#列
下一步
结束 如果
结束 使用
conn.Close()
cmd.Dispose()
conn.Dispose()
< span class =code-keyword>结束 使用
结束 使用
Catch ex As 例外
TextBox6.Text = 用户名:& ; ex.ToString()
结束 尝试
解决方案
Hello Friend ...试试这个
SELECT Count(*)FROM INFORMATION_SCHEMA.Columns其中TABLE_NAME ='YourTableName '
谢谢
你可以使用FieldCount property [ ^ ]。
这里是一个示例 - 获取SqlDataReader中的列数 [ ^ ]。
试试吧是..
SELECT COUNT(COLUMN_NAME)FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='TableName'
I am trying to find the number of columns in my table: Table1.
How do I do that?
Dim connStr, cmdStr As String
Try
connStr="connection string works"
cmdStr = "SELECT * FROM [Table1];"
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
Using myreader = cmd.ExecuteReader()
If myreader.Read() Then
For Each k In columns
'How do you find # of columns
Next
End If
End Using
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
TextBox6.Text = "Username: " & ex.ToString()
End Try
解决方案
Hello Friend...Try This
SELECT Count(*) FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'YourTableName'
Thanks
You can use FieldCount property[^].
Here is an example - Get number of columns in SqlDataReader[^].
try this..
SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TableName'
这篇关于如何查找表格中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文