Pass data to SQL Server

how to pass parameter in sql query
how to pass query as parameter to stored procedure in sql server
sql server agent job pass parameters between steps
how to pass variable in sql query
sql server pass table variable to stored procedure
how to pass parameter in dynamic sql query
execute stored procedure sql server with input parameters
how to pass string variable in sql query

Aim: to pass data from my Webform to SQL Server using a stored procedure. I believe the code is correct apart from the line for the connectionstring but am unsure what it should be.

Issue: passing data from a string to SQL Server via a stored procedure.

Specifically the connection string line, highlighted is ConfigurationManager. I've based my code on my VB.Net website code but can't crack this last syntax.

Code:

Dim constr As String = ConfigurationManager.ConnectionStrings("test").ConnectionString

Using con As New SqlConnection(constr)
    Using cmd As New SqlCommand("InsertXML")
        cmd.Connection = con
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@xml", survey.JobId)

        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
    End Using
End Using

app.config:

<configuration>
    <connectionStrings>
        <add name="Test" 
             connectionString="Data Source=.\sqlexpress;Initial Catalog=TEST;Integrated Security=True"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Using Parameters for SQL Server Queries and Stored Procedures, In this tip we look at different ways to pass in values as parameters to queries and the advantages and disadvantages. Solution. Properly  Method 1: Pass data via an Extended Property between SQL Server Agent Job Steps An extended property is a good place for us to store temporary values as its initial purpose is for "documentation" of database objects. To make things simpler, we will add extended properties to TempDB to pass the data between job steps.

I think you have not added the namespace. If your error is "Name 'ConfigurationManager' is not declared", then add the namespace:-

Imports System.Configuration

If this does not solve it, add reference to System.configuration

Specify Parameters, The following examples demonstrate passing parameter values to the procedure uspGetWhereUsedProductID . They illustrate how to pass  To pass dates to SQL Server from Dexterity, use the sqlDate function instead of the str() function. The sqlDate function is built into Microsoft Dynamics GP. To format a date, you can call this function in the code that you write.

you wrote test but you need to write: Test

ConfigurationManager.ConnectionStrings("Test").ConnectionString

Passing Data table as Parameter to Stored Procedures – {coding}Sight, The aticle describes the process of passing SQL Server data table as a parameter to stored procedures. This year’s PASS Summit conference, the largest gathering of data professionals focused on the Microsoft platform, will be a virtual-only event for the first time.. This will make PASS Virtual Summit 2020 more accessible than ever, giving attendees from around the world the opportunity to network, speak, and learn from the comfort of their own homes at a fraction of the cost of previous PASS

this may work:

 Private conn As SqlConnection
 Private command As SqlCommand



    Public Sub New()
    conn = New SqlConnection()
    conn.ConnectionString = ConfigurationManager.ConnectionStrings("YOUR_Database_Name").ToString()
    command = New SqlCommand()
    command.Connection = conn
End Sub

in the web.config:

 <connectionStrings>
<add name="YOUR_Database_Name" connectionString="Data Source=DATABASE_Location;Initial Catalog=###;Persist Security Info=True;User ID=Username;Password=Password" providerName="System.Data.SqlClient"/>

Table-Valued Parameters in SQL Server, In this manner, the multiple parameter values can pass as an input to the stored and then they can be handled by the stored procedure. In this first  First, the code retrieves data from a source table in a SQLServerDataTable object, defines its schema, and populates the table with data. The code then configures a SQLServerPreparedStatement that passes this data table as a table-valued parameter to SQL Server. /* Assumes connection is an active Connection object.

Pass data to SQL Server, You must use the namespace System.Configuration. And need to add the reference to the assembly System.Configuration.dll. To add the  Open SSDT ( SQL Server Data Tools) and create new SSIS Package. After that go ahead and create variables so we can use them in configuration to pass values anytime our requirement change. ArchiveFolder: Provide the folder path where you would like to move files after loading.

Passing Table to a Store Procedure Parameter in SQL Server 2012, In this article, I described how to pass a table to a Stored Procedure parameter in SQL Server.

Passing Table to a Function Parameter in SQL Server 2012, In this article, I describe how to pass a table to a function parameter in SQL Server.

Comments
  • What is the problem?
  • Error is "ConfigurationManager is not declated" but not of the Visual Studio drop down suggestions fix it.
  • What is your question??
  • Added notes above. Basically the connection string line is based on websites I've build not webforms and it's not right, but I'm unsure of the right syntax.
  • I added System.Configuration as "Imports System.Configuration" as it's VB.NET. I'm using Visual Studio to edit so had no tab but went in via "Project", "Add Reference" thanks. Looks good, I'll retest now.
  • sorry for that I'm not well familiar with VB
  • No worries, close enough and use to using code from C#
  • Fair comment but not the issue sadly.