位置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())

查看:109
本文介绍了位置0没有行.........(第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 populating dt ... you are filling the dataset but not the datatable. Try adding a line dt = ds.Tables(0) or something similar


这篇关于位置0没有行.........(第416行:textname.text = dt.rows(0)(" name")。tostring())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆