Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';t从VB.NET连接到SQL Server_.net_Sql Server_Vb.net - Fatal编程技术网

我能';t从VB.NET连接到SQL Server

我能';t从VB.NET连接到SQL Server,.net,sql-server,vb.net,.net,Sql Server,Vb.net,我无法使用vb.net连接到SQL Server 这是我的密码: Imports system.data.sqlclient PUBLIC CLASS customer_typer Dim connectionstring as string = "data source = wisdon; initial catalog = stock_management; user id = sa; password = managerz " Dim mycommand as new

我无法使用vb.net连接到SQL Server

这是我的密码:

Imports system.data.sqlclient

PUBLIC CLASS customer_typer

    Dim connectionstring as string = "data source = wisdon; initial catalog = stock_management; user id = sa; password = managerz "

    Dim mycommand as new sqlcommand
    Dim myconnection = new sqlcomma d (connectionstring)

    PRIVATE SUB CUSTOMER_BT
        dim sqlstr as string
        Sqlstr = " insert into customer_type(customer_type) values"  & _
            "(' " & customertyper_txt.text & " ')"
        Mycommand = new sqlclient.sqlcommand (sqlstr, myconnection)

        Mycommand.executeNonQuery ()

        Myconnection.close
Customer\u type
是我正在编写代码的按钮


Customertype_txt
是您忘记打开连接的文本框。您还试图将连接声明为命令。正如@marc_建议的那样,我添加了一些参数来防止sql注入。 Using…End Using语句确保即使出现错误,也会关闭和释放对象

Using myconnection = New SqlConnection(connectionstring)
            Dim Sqlstr As String = " insert into customer_type(customer_type) values(@CustomerType);"
            Using mycommand As New SqlClient.SqlCommand(Sqlstr, myconnection)
                mycommand.Parameters.Add("@CustomerType", SqlDbType.VarChar).Value = customertyper_txt.text
                myconnection.Open()
                mycommand.ExecuteNonQuery()
                myconnection.Close()
            End Using
End Using

我不能连接具体是什么意思?是什么阻止你连接?你收到错误信息了吗?如果是,这是什么信息?您没有提供我们可以使用的详细信息,我们无法使用您发布的内容访问您的数据库进行测试。你的工作是清楚地描述问题并提供细节,我们的工作是试图解决你的问题。请你的帖子做你的工作,这样我们就可以做我们的。至少有一个打字错误
Dim my connection=new-sqlcomma d(connectionstring)
此外,您可能应该在尝试运行查询之前检查
new-sqlcommand(connectionstring)
,这就是您的意思您不应该将SQL语句连接在一起-使用参数化查询来避免SQL注入-签出