Sql server Single Transction中的多记录删除 [英] Multiple Record Delete in Sql server Single Transction

查看:85
本文介绍了Sql server Single Transction中的多记录删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.aspsnippets.com/Articles/Pass-multiple-records-rows-to-a-Stored-Procedure-in-SQL-Server-using-C-and-VBNet.aspx [ ^ ]我是用户此链接



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

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



执行程序时我收到错误



消息137,级别16,状态1,过程Insert_Customers,第7行

必须声明标量变量@tblCustomers。





Plz任何帮助我先生.......................


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.......................

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;
        }
    }
}

推荐答案

tblCustomers是您的自定义类型,而EmailID是压缩整数(ID)或字符串(电子邮件)...通过插入,tblCustomers甚至不包含emailID字段。



错误告诉您服务器需要SCALAR变量以便是你必须提供的。



示例:

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:
DELETE FROM Email
WHERE emailID IN (SELECT emailID FROM @tblCustomers)

-- this assumes tblCustomers really contains such field otherwise, you cannot do it.


使用System;

使用System.Collections.Generi c;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Windows.Forms;

使用System.IO;



命名空间Code.SearchFileContent

{

公共部分类Form1:表格

{

public Form1()

{

InitializeComponent();

}



private void button1_Click(object sender,EventArgs e)

{

SearchFileContent(@E:\Projects\Code.SearchFileContent\Code。 SearchFileContent);

}

public void SearchFileContent(string pDirectoryPath)

{

//修改此路径有必要的。





//拍摄文件系统的快照。

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(pDirectoryPath);



//此方法假设应用程序具有发现权限

//适用于所有文件夹指定的路径。

IEnumerable< system.io.fileinfo> fileList = dir.GetFiles(*。*,System.IO.SearchOption.AllDirectories);



string searchTerm = @Visual Studio;



//搜索每个文件的内容。

//使用RegEx类创建的正则表达式

//可以用来代替Contains方法。

// queryMatchingFiles是一个IEnumerable< string>。



//执行查询。

string ssss = string.Empty;

Console.WriteLine(术语\{0} \见于:,searchTerm);

string fileText = string.Empty;

string line;

StringBuilder sb = new StringBuilder();



foreach(fileList中的FileInfo sss)

{

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);))

{

//这会将文本和换行符附加到StringBuilder缓冲区中

sb.AppendLine(sss.FullName ++ line.ToString()+ lineno + Environment .NewLine);

}

lineno ++;

}



} < br $>


}





int counter = 0;



label1.Text =;

textBox1.Text = sb.ToString();

//保留控制台窗口在调试模式下打开。



}



//读取文件内容。

静态字符串GetFileText(字符串名称)

{

string fileContents = String.Empty;



//如果文件已被删除,因为我们拍摄了快照,请忽略它并返回空字符串。

if(System.IO.File.Exists(name))

{

fileContents = System.IO.File.ReadAllText(name) ;



}

返回fileContents;

}

}

}
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;
}
}
}


这篇关于Sql server Single Transction中的多记录删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆