Sql server VB.NET/SQL System.Argument异常

Sql server VB.NET/SQL System.Argument异常,sql-server,vb.net,Sql Server,Vb.net,我是编程新手,在构建应用程序的过程中,我遇到了几个错误。Visual Studio错误框的附加信息部分提供以下消息: System.Data.dll中发生类型为“System.ArgumentException”的未处理异常 其他信息:初始化字符串的格式不符合从索引0开始的规范 当应用程序尝试执行以下代码行时,会发生这种情况: Dim da As New SqlDataAdapter(sql, cs) 我一直在努力解决这个问题,但毫无结果。谢谢您的帮助!请在下面查找该类的其他信息/代码

我是编程新手,在构建应用程序的过程中,我遇到了几个错误。Visual Studio错误框的附加信息部分提供以下消息:

System.Data.dll中发生类型为“System.ArgumentException”的未处理异常

其他信息:初始化字符串的格式不符合从索引0开始的规范

当应用程序尝试执行以下代码行时,会发生这种情况:

    Dim da As New SqlDataAdapter(sql, cs)
我一直在努力解决这个问题,但毫无结果。谢谢您的帮助!请在下面查找该类的其他信息/代码:

Imports System.Data
Imports System.Data.SqlClient


Public Class DButil
    Public cs As String

    Public Function GetDataView(ByVal sql As String) As DataView
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(sql, cs)

        da.Fill(ds)

        Dim dv As New DataView(ds.Tables(0))
        Return dv
    End Function

    Public Sub New()

        cs = "Data Source=(LocalDB)\v11.0"
        cs += "Data Source=(LocalDB)'C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True;"
        cs += "Integrated Security =True;Connect Timeout=30"
    End Sub

End Class

谢谢你的回复,史蒂夫。这删除了以下行中的错误:Dim da As New SqlDataAdapter(sql,cs)。下面一行出现错误:da.Fill(ds)。此错误表示SqlException未处理,并且表示一个非布尔类型的表达式,其中条件应位于“,”附近。想法

您的连接字符串确实错误。
对于Sql Server 2012和LocalDB实例,您需要

Public Sub New()
    cs =  "Server=(LocalDB)\v11.0;"
    cs += "Integrated Security=True;"
    cs += "AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"
End Sub

请参阅Sql Server连接字符串示例,网址为

您的连接字符串确实错误。
对于Sql Server 2012和LocalDB实例,您需要

Public Sub New()
    cs =  "Server=(LocalDB)\v11.0;"
    cs += "Integrated Security=True;"
    cs += "AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"
End Sub

请参阅Sql Server连接字符串示例,网址为

您的连接字符串确实错误。
对于Sql Server 2012和LocalDB实例,您需要

Public Sub New()
    cs =  "Server=(LocalDB)\v11.0;"
    cs += "Integrated Security=True;"
    cs += "AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"
End Sub

请参阅Sql Server连接字符串示例,网址为

您的连接字符串确实错误。
对于Sql Server 2012和LocalDB实例,您需要

Public Sub New()
    cs =  "Server=(LocalDB)\v11.0;"
    cs += "Integrated Security=True;"
    cs += "AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"
End Sub

请参见

上的Sql Server连接字符串示例。您的连接字符串肯定是错误的。看看

下面是一个如何查询数据库并返回dataview的示例

Public Function GetDataView(sql As String) As DataView
Dim cs = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"

Using cnn As New SqlConnection(cs)
  Using cmd As New SqlCommand(sql, cnn)
    Try
      cnn.Open()
      Dim t As New DataTable
      t.Load(cmd.ExecuteReader)
      Return New DataView(t)
    Catch ex As Exception
      ''handle the error
    End Try
  End Using
End Using
End Function

你的连接字符串肯定是错的。看看

下面是一个如何查询数据库并返回dataview的示例

Public Function GetDataView(sql As String) As DataView
Dim cs = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"

Using cnn As New SqlConnection(cs)
  Using cmd As New SqlCommand(sql, cnn)
    Try
      cnn.Open()
      Dim t As New DataTable
      t.Load(cmd.ExecuteReader)
      Return New DataView(t)
    Catch ex As Exception
      ''handle the error
    End Try
  End Using
End Using
End Function

你的连接字符串肯定是错的。看看

下面是一个如何查询数据库并返回dataview的示例

Public Function GetDataView(sql As String) As DataView
Dim cs = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"

Using cnn As New SqlConnection(cs)
  Using cmd As New SqlCommand(sql, cnn)
    Try
      cnn.Open()
      Dim t As New DataTable
      t.Load(cmd.ExecuteReader)
      Return New DataView(t)
    Catch ex As Exception
      ''handle the error
    End Try
  End Using
End Using
End Function

你的连接字符串肯定是错的。看看

下面是一个如何查询数据库并返回dataview的示例

Public Function GetDataView(sql As String) As DataView
Dim cs = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"

Using cnn As New SqlConnection(cs)
  Using cmd As New SqlCommand(sql, cnn)
    Try
      cnn.Open()
      Dim t As New DataTable
      t.Load(cmd.ExecuteReader)
      Return New DataView(t)
    Catch ex As Exception
      ''handle the error
    End Try
  End Using
End Using
End Function


乍一看,您的连接字符串看起来不正确。您正在尝试连接到哪种类型的数据库?谢谢您的回复。这是一个SQL数据库。需要查看传递到
GetDataView
的变量
SQL
的内容。乍一看,您的连接字符串看起来不正确。您正在尝试连接到哪种类型的数据库?谢谢您的回复。这是一个SQL数据库。需要查看传递到
GetDataView
的变量
SQL
的内容。乍一看,您的连接字符串看起来不正确。您正在尝试连接到哪种类型的数据库?谢谢您的回复。这是一个SQL数据库。需要查看传递到
GetDataView
的变量
SQL
的内容。乍一看,您的连接字符串看起来不正确。您正在尝试连接到哪种类型的数据库?谢谢您的回复。这是一个SQL数据库。需要查看传递给
GetDataView
的变量
SQL
的内容。感谢您的回复,Steve。这删除了以下行中的错误:Dim da As New SqlDataAdapter(sql,cs)。下面一行出现错误:da.Fill(ds)。此错误表示SqlException未处理,并且表示一个非布尔类型的表达式,其中条件应位于“,”附近。想法?嗯,这肯定是由您的sql文本引起的。把这些信息添加到你上面的问题中,这样每个人都可以查看它。史蒂夫,谢谢你的回答。这删除了以下行中的错误:Dim da As New SqlDataAdapter(sql,cs)。下面一行出现错误:da.Fill(ds)。此错误表示SqlException未处理,并且表示一个非布尔类型的表达式,其中条件应位于“,”附近。想法?嗯,这肯定是由您的sql文本引起的。把这些信息添加到你上面的问题中,这样每个人都可以查看它。史蒂夫,谢谢你的回答。这删除了以下行中的错误:Dim da As New SqlDataAdapter(sql,cs)。下面一行出现错误:da.Fill(ds)。此错误表示SqlException未处理,并且表示一个非布尔类型的表达式,其中条件应位于“,”附近。想法?嗯,这肯定是由您的sql文本引起的。把这些信息添加到你上面的问题中,这样每个人都可以查看它。史蒂夫,谢谢你的回答。这删除了以下行中的错误:Dim da As New SqlDataAdapter(sql,cs)。下面一行出现错误:da.Fill(ds)。此错误表示SqlException未处理,并且表示一个非布尔类型的表达式,其中条件应位于“,”附近。想法?嗯,这肯定是由您的sql文本引起的。将这些信息添加到上面的问题中,以便每个人都可以查看