Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
http://www.aspsnippets.com/Articles/Pass-multiple-records-rows-to-a-Stored-Procedure-in-SQL-Server-using-C-and-VBNet.aspx[^] I am user this Link

SQL
CREATE PROCEDURE [dbo].[Insert_Customers]
      @tblCustomers CustomerType READONLY
AS
BEGIN
      SET NOCOUNT ON;
     
     INSERT INTO Customers(CustomerId, Name, Country)
      SELECT Id, Name, Country FROM @tblCustomers -- In this Area i need delete from Email where EmailID=@tblCustomers

END

While Excuting Procedure i am getting error

Msg 137, Level 16, State 1, Procedure Insert_Customers, Line 7
Must declare the scalar variable "@tblCustomers".


Plz Any Help me Sir.......................
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Code.SearchFileContent
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SearchFileContent(@"E:\Projects\Code.SearchFileContent\Code.SearchFileContent");
        }
        public void SearchFileContent(string pDirectoryPath)
        {
            // Modify this path as necessary. 


            // Take a snapshot of the file system.
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(pDirectoryPath);

            // This method assumes that the application has discovery permissions 
            // for all folders under the specified path.
            IEnumerable<system.io.fileinfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

            string searchTerm = @"Visual Studio";

            // Search the contents of each file. 
            // A regular expression created with the RegEx class 
            // could be used instead of the Contains method. 
            // queryMatchingFiles is an IEnumerable<string>. 

            // Execute the query.
            string ssss = string.Empty;
            Console.WriteLine("The term \"{0}\" was found in:", searchTerm);
            string fileText = string.Empty;
            string line;
            StringBuilder sb = new StringBuilder();
            
            foreach (FileInfo sss in fileList)
            {
                fileText += GetFileText(sss.FullName);
                label1.Text = sss.FullName;
                using (System.IO.StreamReader file = new System.IO.StreamReader(sss.FullName))
                {
                    int lineno = 1;
                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.Contains("fileText += GetFileText(sss.FullName);"))
                        {
                            // This append the text and a newline into the StringBuilder buffer       
                            sb.AppendLine(sss.FullName +  "" + line.ToString() + lineno + Environment.NewLine);
                        }
                        lineno++;
                    }

                }

            }


            int counter = 0;

            label1.Text = "";
            textBox1.Text = sb.ToString();
            // Keep the console window open in debug mode.

        }

        // Read the contents of the file. 
        static string GetFileText(string name)
        {
            string fileContents = String.Empty;

            // If the file has been deleted since we took  
            // the snapshot, ignore it and return the empty string. 
            if (System.IO.File.Exists(name))
            {
                fileContents = System.IO.File.ReadAllText(name);

            }
            return fileContents;
        }
    }
}
Posted
Updated 14-Dec-14 6:44am
v3
Comments
syed shanu 5-Dec-14 2:13am    
I think you need something like this :


DECLARE @tblCustomers AS NVARCHAR(MAX),
@SQLquery AS NVARCHAR(MAX)


set @tblCustomers='tblCustomers';

set @SQLquery = N' delete from EMAIL where EmailID
in (select EmailID from '+@tblCustomers+')'

exec sp_executesql @SQLquery;
Thava Rajan 15-Dec-14 0:02am    
how did you execute this procedure in your code?
please provide some code sample to rectify your problem

tblCustomers is your custom type, while EmailID is pressumably integer (ID) or string (email)...by your insert, tblCustomers does not even contain emailID field.

The error tells you the server expects SCALAR variable so that is what you have to provide.

Example:
SQL
DELETE FROM Email
WHERE emailID IN (SELECT emailID FROM @tblCustomers)

-- this assumes tblCustomers really contains such field otherwise, you cannot do it.
 
Share this answer
 
Comments
Shweta N Mishra 5-Dec-14 3:28am    
+5
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Code.SearchFileContent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SearchFileContent(@"E:\Projects\Code.SearchFileContent\Code.SearchFileContent");
}
public void SearchFileContent(string pDirectoryPath)
{
// Modify this path as necessary.


// Take a snapshot of the file system.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(pDirectoryPath);

// This method assumes that the application has discovery permissions
// for all folders under the specified path.
IEnumerable<system.io.fileinfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

string searchTerm = @"Visual Studio";

// Search the contents of each file.
// A regular expression created with the RegEx class
// could be used instead of the Contains method.
// queryMatchingFiles is an IEnumerable<string>.

// Execute the query.
string ssss = string.Empty;
Console.WriteLine("The term \"{0}\" was found in:", searchTerm);
string fileText = string.Empty;
string line;
StringBuilder sb = new StringBuilder();

foreach (FileInfo sss in fileList)
{
fileText += GetFileText(sss.FullName);
label1.Text = sss.FullName;
using (System.IO.StreamReader file = new System.IO.StreamReader(sss.FullName))
{
int lineno = 1;
while ((line = file.ReadLine()) != null)
{
if (line.Contains("fileText += GetFileText(sss.FullName);"))
{
// This append the text and a newline into the StringBuilder buffer
sb.AppendLine(sss.FullName + "" + line.ToString() + lineno + Environment.NewLine);
}
lineno++;
}

}

}


int counter = 0;

label1.Text = "";
textBox1.Text = sb.ToString();
// Keep the console window open in debug mode.

}

// Read the contents of the file.
static string GetFileText(string name)
{
string fileContents = String.Empty;

// If the file has been deleted since we took
// the snapshot, ignore it and return the empty string.
if (System.IO.File.Exists(name))
{
fileContents = System.IO.File.ReadAllText(name);

}
return fileContents;
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900