带字符串的存储过程 [英] stored procedure with string

查看:128
本文介绍了带字符串的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我有一个带有两个参数的存储过程

Hello!

i have one stored prosedure with two parameters

proc_udatabase (@ string1, @string2) 


如何从c Sharp拨打电话


how to call from c sharp

string querry = ("proc_urdatabase" + "name" + "24") i want to check weather it exist in database or not


如何在C Sharp中进行操作

因为


how to do it in c sharp

because

SqlDataReader rdr =StoredProcedureCommand.ExecuteReader(); is not working               
SqlDataReader rdr = command.ExecuteReader(); is working but not executing while after it

推荐答案

类似这样的东西(注意,我没有包含try/catch/finally块):

Something like this (notice I didn''t include try/catch/finally block):

SqlConnection conn   = new SqlConnection(connectionstring);
SqlCommand    cmd    = new SqlCommand("proc_udatabase", conn);
SqlDataReader reader = null;
Datatable     data   = new  DataTable();

conn.Open();
cmd.Parameters.Add(new SqlParameter("@string1", "name");
cmd.Parameters.Add(new SqlParameter("@string2", "24");
reader = cmd.ExecuteReader();
if (reader != null)
{
    data.Load(reader);
}
conn.Close();




执行命令之前

添加此

Hi,

Before executing the command

add this

command.CommandType=CommandType.StoredProcedure


这篇关于带字符串的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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