SQL 使用sql数据库中的文本框显示记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15874063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
display records using textbox from sql database
提问by ivandinglasan
This is my code for displaying records from database to combo box but, when I edit the code and make it for textbox, .DataSource
and .ValueMember
are not working for textboxes.
这是我用于将记录从数据库显示到组合框的代码,但是,当我编辑代码并将其用于文本框时,.DataSource
并且.ValueMember
不适用于文本框。
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim dt As New DataTable
sqlconn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn)
da.Fill(dt)
cmbLocationCode.DataSource = dt
cmbLocationCode.ValueMember = "OE_ID"
sqlconn.Close()
What is the corresponding code for displaying data from database using textboxes?
使用文本框显示数据库中数据的相应代码是什么?
回答by Praveen Nambiar
You can simple do this:
你可以简单地做到这一点:
yourTextBox.Text = dt.Rows(0)("ColumnName").ToString()
回答by ivandinglasan
it does not diplay data sir
它不显示数据先生
Public Sub PopulateOeqProfileForm()
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim dt As New DataTable
sqlconn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentProfile", sqlconn)
da.Fill(dt)
txtOEID.Text = dt.Rows(0)("OE_ID").ToString()
sqlconn.Close()
End Sub
回答by Thangamani Palanisamy
There is no property like datasource,valuemember and display name will not availiable. please refer this link.
没有像数据源、值成员和显示名称这样的属性将不可用。请参考这个链接。
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox_properties(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox_properties(v=vs.90).aspx
You only able to assign values from database or local assigment. You should do in the following ways . Assume that if you have txtUserNametextbox , you should assign the follwing way
您只能从数据库或本地分配中分配值。你应该从以下几个方面做。假设如果你有txtUserName文本框,你应该分配以下方式
txtLocationCode=dt.rows[0]["column name"].tostring()
txtLocationCode=dt.rows[0]["列名"].tostring()
There is no property datasource is not availiable since it not collection object. It holds only one column value from database.
没有属性数据源不可用,因为它不是集合对象。它只保存来自数据库的一列值。
Update :
更新 :
Public Sub PopulateOeqProfileForm()
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim dt As New DataTable
sqlconn.Open()
Dim SelectCommand As New SqlClient.SqlCommand (SELECT OE_ID FROM tblOfficeEquipmentProfile, sqlconn)
txtOEID.Text = Cstr(SelectCommand.ExecuteScalar())
sqlconn.Close()
End Sub
Hope this helps
希望这可以帮助