[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Parameter Select Statement

Posted on 2012-09-20
7
Medium Priority
?
608 Views
Last Modified: 2012-09-29
Hello,

What would a Select statement look like in SQL Parameter?

Thank you!

 public DataTable SelectFromTable(string myString)
        {
            string sqlCall = "SELECT ID, Name, Status, Date FROM dbo.tbl_myTable where id in (" + myString+ ") Order by ID Desc";
            SqlDataAdapter da = new SqlDataAdapter(sql, cnstr);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

Open in new window

0
Comment
Question by:Rad1
  • 4
  • 3
7 Comments
 
LVL 25

Expert Comment

by:TempDBA
ID: 38419023
Can you be more clearer?
0
 

Author Comment

by:Rad1
ID: 38419107
Need to covert the SQL function to SQL parameters type
Function.
0
 

Accepted Solution

by:
Rad1 earned 0 total points
ID: 38430978
Here is the answer:

public DataTable SelectFromTable(string myString)
        {
           string sqlCall = "SELECT ID, Name, Status, Date FROM dbo.tbl_myTable where id in (" + @myString+ ") Order by ID Desc";
           SqlConnection conn = new SqlConnection(cnstr);
           conn.Open();
           SqlCommand cmd = new SqlCommand(sql, conn);
           cmd.Parameters.AddWithValue("@myString", myString
	   SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           conn.Close();
           conn.Dispose();
           return dt;
        }	
                               

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 25

Expert Comment

by:TempDBA
ID: 38431550
And how?
0
 

Author Comment

by:Rad1
ID: 38431572
See the code posted.
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 38431662
Good. Thanks.
0
 

Author Closing Comment

by:Rad1
ID: 38446933
I solved it!
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question