刚看了关于参数化查询的一些文章资料之类的,但是我就是想在SQL2005里,到底该怎么使用哈  
看到有的资料上说需要visual studio 2005?  什么sqlcommand之类的
但是我想在SQL SEVER management studio中 可以使用这些么?还有就是如果不使用,又该怎样实现啊,比如下面这个例子:例: 编写一个自定义函数,能够实现参数化查询的功能。
自己设定函数的具体要求,然后编写出来。这个该怎么实现呢--------------------
盼解答  非常感激了

解决方案 »

  1.   

    vs2005里的一段代码:  cmd = new SqlCommand("CHECKDB.dbo.pr_ProDalMonitor", conn);
                    cmd.CommandType = CommandType.StoredProcedure;                SqlParameter param1 = cmd.Parameters.Add("@NetType", SqlDbType.VarChar, 8);
                    param1.Direction = ParameterDirection.Input;                SqlParameter param2 = cmd.Parameters.Add("@Time", SqlDbType.DateTime);
                    param2.Direction = ParameterDirection.Input;                SqlParameter param3 = cmd.Parameters.Add("@Indicator", SqlDbType.VarChar,64);
                    param3.Direction = ParameterDirection.Input;                SqlParameter param4 = cmd.Parameters.Add("@befHour", SqlDbType.TinyInt);
                    param4.Direction = ParameterDirection.Input;                SqlParameter param5 = cmd.Parameters.Add("@bitHis", SqlDbType.TinyInt);
                    param5.Direction = ParameterDirection.Input;                //*************************************************
                    if (tabCtrl.SelectedIndex == 0)
                    {
                        param1.Value = "MSC";
                        string befHour = GetXmlNodeAttribute("root/Msc", "befHour");
                        param4.Value = Convert.ToInt16(befHour);
                    }
                    else if (tabCtrl.SelectedIndex == 1)
                    {
                        param1.Value = "BSC";
                        string befHour = GetXmlNodeAttribute("root/Bsc", "befHour");
                        param4.Value = Convert.ToInt16(befHour);
                    }
                    else if (tabCtrl.SelectedIndex == 2)
                    {
                        param1.Value = "SITE";
                        string befHour = GetXmlNodeAttribute("root/Site", "befHour");
                        param4.Value = Convert.ToInt16(befHour);
                    }
                    else if (tabCtrl.SelectedIndex == 3)
                    {
                        param1.Value = "BTS";
                        string befHour = GetXmlNodeAttribute("root/Bts", "befHour");
                        param4.Value = Convert.ToInt16(befHour);
                    }                param2.Value = dtpDate.Value;
                    param3.Value = cboIndicator.Tag;
    这就是你说的 参数查询吧
      

  2.   

    如果不要sqlcommand之类的呢?
    必须要这个么?
    求解啊
      

  3.   

    这种查询 不是必须的,但是这种查询 效率比较好,推荐使用。
    而且代码可以复用,你随时可以传任意参数执行。SQL SEVER management studio 是没有这种查询的。
      

  4.   

     因为只有command才有commandtype表示执行的是存储过程
     cmd.CommandType = CommandType.StoredProcedure;