System.Data.SqlClient.SqlException: 列名 '计算机科学系' 无效。 20
ImportsSystem.DataImportsSystem.Data.SqlClient'导入使用SQLSERVER数据库的命名空间PartialClassstu_D...
Imports System.Data
Imports System.Data.SqlClient '导入使用SQL SERVER 数据库的命名空间
Partial Class stu_Default2
Inherits System.Web.UI.Page
Protected Sub DpUName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DpUName.SelectedIndexChanged
Dim ConStr As String ''与数据库连接的语句.
ConStr = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr As String
SqlStr = "Select distinct [tname] from keti where xibie=DpUName.SelectedValue"
Dim Da As New SqlDataAdapter(SqlStr, ConStr)
Dim Ds As New DataSet
Dim MyTable As New DataTable
Da.Fill(Ds, "keti")
MyTable = Ds.Tables(0)
If MyTable.Rows.Count <> 0 Then
DpU1Name.DataSource = MyTable
DpU1Name.DataTextField = "tname"
DpU1Name.DataBind()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ConStr As String ''与数据库连接的语句.
ConStr = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr As String
SqlStr = "Select distinct [xibie] from keti"
Dim Da As New SqlDataAdapter(SqlStr, ConStr)
Dim Ds As New DataSet
Dim MyTable As New DataTable
Da.Fill(Ds, "keti")
MyTable = Ds.Tables(0)
If MyTable.Rows.Count <> 0 Then
DpUName.DataSource = MyTable
DpUName.DataTextField = "xibie"
DpUName.DataBind()
End If
Dim ConStr1 As String ''与数据库连接的语句.
ConStr1 = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr1 As String
SqlStr1 = "Select distinct [tname] from keti where xibie=" + Me.DpUName.SelectedValue
Dim Da1 As New SqlDataAdapter(SqlStr1, ConStr1)
Dim Ds1 As New DataSet
Dim MyTable1 As New DataTable
Da1.Fill(Ds1, "keti")
MyTable1 = Ds1.Tables(0)
If MyTable1.Rows.Count <> 0 Then
DpU1Name.DataSource = MyTable1
DpU1Name.DataTextField = "tname"
DpU1Name.DataBind()
End If
End Sub
End Class
运行时,提示System.Data.SqlClient.SqlException: 列名 '计算机科学系' 无效。
注:”计算机科学系“ 是xibie字段中的一类容。 展开
Imports System.Data.SqlClient '导入使用SQL SERVER 数据库的命名空间
Partial Class stu_Default2
Inherits System.Web.UI.Page
Protected Sub DpUName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DpUName.SelectedIndexChanged
Dim ConStr As String ''与数据库连接的语句.
ConStr = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr As String
SqlStr = "Select distinct [tname] from keti where xibie=DpUName.SelectedValue"
Dim Da As New SqlDataAdapter(SqlStr, ConStr)
Dim Ds As New DataSet
Dim MyTable As New DataTable
Da.Fill(Ds, "keti")
MyTable = Ds.Tables(0)
If MyTable.Rows.Count <> 0 Then
DpU1Name.DataSource = MyTable
DpU1Name.DataTextField = "tname"
DpU1Name.DataBind()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ConStr As String ''与数据库连接的语句.
ConStr = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr As String
SqlStr = "Select distinct [xibie] from keti"
Dim Da As New SqlDataAdapter(SqlStr, ConStr)
Dim Ds As New DataSet
Dim MyTable As New DataTable
Da.Fill(Ds, "keti")
MyTable = Ds.Tables(0)
If MyTable.Rows.Count <> 0 Then
DpUName.DataSource = MyTable
DpUName.DataTextField = "xibie"
DpUName.DataBind()
End If
Dim ConStr1 As String ''与数据库连接的语句.
ConStr1 = "Data Source=localhost; Initial Catalog=data; Persist Security Info=False; Integrated Security=SSPI"
Dim SqlStr1 As String
SqlStr1 = "Select distinct [tname] from keti where xibie=" + Me.DpUName.SelectedValue
Dim Da1 As New SqlDataAdapter(SqlStr1, ConStr1)
Dim Ds1 As New DataSet
Dim MyTable1 As New DataTable
Da1.Fill(Ds1, "keti")
MyTable1 = Ds1.Tables(0)
If MyTable1.Rows.Count <> 0 Then
DpU1Name.DataSource = MyTable1
DpU1Name.DataTextField = "tname"
DpU1Name.DataBind()
End If
End Sub
End Class
运行时,提示System.Data.SqlClient.SqlException: 列名 '计算机科学系' 无效。
注:”计算机科学系“ 是xibie字段中的一类容。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询