Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以任意顺序将数据直接从MySQL列获取到textbox?Textbox1=Column1,Textbox2=Column4,Textbox3=Column8_Mysql_Excel_Vba - Fatal编程技术网

如何以任意顺序将数据直接从MySQL列获取到textbox?Textbox1=Column1,Textbox2=Column4,Textbox3=Column8

如何以任意顺序将数据直接从MySQL列获取到textbox?Textbox1=Column1,Textbox2=Column4,Textbox3=Column8,mysql,excel,vba,Mysql,Excel,Vba,现在我正在使用“选择*表格…”和一个记录集,通过记录集字段的编号将值扔到textbox中textbox1=rs.Fields(0)textbox2=rs.Fields(1),依此类推。。。它是有效的,但每次我对数据库进行更改时,都会让人感到痛苦。。。要将所有内容放回原位,是否仍需要使用数据库的列名将值放入文本框中textbox1=Column1 textbox2=Column2因此向数据库添加新列并不重要,因为它们将由列标题选择 我用它来用excel中的userform更新数据库中的值,为此,我

现在我正在使用“选择*表格…”和一个记录集,通过记录集字段的编号将值扔到textbox中
textbox1=rs.Fields(0)textbox2=rs.Fields(1)
,依此类推。。。它是有效的,但每次我对数据库进行更改时,都会让人感到痛苦。。。要将所有内容放回原位,是否仍需要使用数据库的列名将值放入文本框中
textbox1=Column1 textbox2=Column2
因此向数据库添加新列并不重要,因为它们将由列标题选择

我用它来用excel中的userform更新数据库中的值,为此,我使用“更新表集COLUMN1=textbox1 COLUMN2=textbox2…”无论如何,我可以用更新的相同方式获得它们,所以如果我更改列数,它不会变得混乱

我所拥有的:

sqlQuery = "SELECT * FROM table WHERE OS ='123'
sqlQuery = sqlQuery & ";"
rs.Source = sqlQuery
Set rs.ActiveConnection = Conn
rs.CursorLocation = adUseClient
rs.Open


For Each field In rs.Fields
    If IsNull(rs.Fields(0)) = False Then Textbox1 = rs.Fields(0)
    If IsNull(rs.Fields(1)) = False Then Textbox2 = rs.Fields(1)
    If IsNull(rs.Fields(2)) = False Then Textbox3 = rs.Fields(2)
    If IsNull(rs.Fields(3)) = False Then Textbox4 = rs.Fields(3)
Next
我需要的是:

sqlQuery = "SELECT * FROM table WHERE OS ='123'
sqlQuery = sqlQuery & ";"
rs.Source = sqlQuery
Set rs.ActiveConnection = Conn
rs.CursorLocation = adUseClient
rs.Open


For Each field In rs.Fields
    If IsNull(rs.Fields(0)) = False Then Textbox1 = Column1Header
    If IsNull(rs.Fields(1)) = False Then Textbox2 = Column2Header
    If IsNull(rs.Fields(2)) = False Then Textbox3 = Column3Header
    If IsNull(rs.Fields(3)) = False Then Textbox4 = Column4Header
next
rs.Fields(“FieldName”)
works

由于
Fields
是记录集对象的默认值,
rs(“FieldName”)
也可以工作


你不必使用索引值。

rs(“FieldName”)
也可以-你不必使用索引值。真的吗?该死的,我会在这里测试!谢谢你,它的工作,因为我需要!