位置0没有行.........(第416行:textname.text = dt.rows(0)(" name")。tostring()) [英] There is no row at position 0.........(line 416: textname.text = dt.rows(0)("name").tostring())
问题描述
我写了这段代码来从数据库中获取数据并将其填入文本框和下拉列表....
更多详细信息:
当我进入textID(id)然后我点击输入名称,生日和招聘日期的文本框,网站,部门,国籍和宗教的下拉列表必须填写我输入的id的数据....
请尽快帮助我:(
和
是否有任何语法代码我在select命令代码(sql server)中编写它
我尝试过:
Hi, i wrote this code to get data from database and fill it in the textbox and dropdownlists....
More details:
when i enter in the textID the (id) then i click enter the textbox for name ,birthdate and hiringdate and the dropdownlist for sites,department,nationality and religions must to fill by the data for the id i entered ....
plz help me as soon as :(
and
is there any syntax code i write it in select command code ( sql server)
What I have tried:
Protected Sub TextID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextID.TextChanged
For i = 0 To GridView1.Rows.Count - 1
Dim con As New SqlConnection
Dim cmd As New SqlCommand("EmployeePro")
Dim Adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
' Dim str As String = ""
'DateTime.TryParseExact(Me.TextBitrh.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, result)
con.ConnectionString = "Server=.;Database=log;User Id=sa; Password=123;"
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
Adapter.SelectCommand = cmd
'cmd.CommandText = "[dbo].[setupEmp]"
cmd.Parameters.Add("@ID", SqlDbType.Int)
cmd.Parameters("@ID").Value = TextID.Text
Session("LoadData") = ds.Tables("tabel1")
con.Open()
Adapter.Fill(ds, "tabel1")
con.Close()
If TextID.Text > 0 Then
TextName.Text = dt.Rows(0)("Name").ToString()
DropSites.Text = dt.Rows(0)("sites2").ToString()
DropDep.Text = dt.Rows(0)("department1").ToString()
DropNat.Text = dt.Rows(0)("Nationalty1").ToString()
DDLRel.Text = dt.Rows(0)("Religions1").ToString()
TextBitrh.Text = dt.Rows(0)("Birth_Date").ToString()
TextHiring.Text = dt.Rows(0)("hiring_date").ToString()
End If
Next
End Sub
推荐答案
您没有填充dt
...您正在填充数据集但不填充数据表。尝试添加一行dt = ds.Tables(0
)或类似的东西
You are not populatingdt
... you are filling the dataset but not the datatable. Try adding a linedt = ds.Tables(0
) or something similar
这篇关于位置0没有行.........(第416行:textname.text = dt.rows(0)(" name")。tostring())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!