Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 19th, 2006, 6:32 AM   #1
Hartigan
Newbie
 
Join Date: Jul 2006
Posts: 2
Rep Power: 0 Hartigan is on a distinguished road
CLR-StoreProcdures

Hi
I have a CLR-Stored Procdure I've compiled it and deployed it but it doesn't work.
The error message says that Subqueries are not allowed in this context,I wonder if you could help me.

by the way I've already reconfigured the Data Base and it's ready to run the CLR-Stored Procdures.

here is the code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void AddGoods(SqlString GoodsID,SqlString TypeName,
        SqlString Unit,SqlString GoodsName,SqlString Amount,SqlString Price,
        SqlString Description)
    {
        using ( SqlConnection cnn = new SqlConnection("context connection=true") )
        {
            SqlCommand cmd = new SqlCommand();
            string strType = " (SELECT TypeID FROM Tbl_TypesOfGoods WHERE TypeName='" + TypeName.ToString() + "')";
            string strUnit = " (SELECT UnitID FROM Tbl_Units WHERE UnitName='" + Unit.ToString() + "')";

            cmd.CommandText = "INSERT INTO Tbl_Goods(GoodsID, TypeID, UnitID, GoodsName, " +
                "Amount, Price, Description)" + " VALUES('" + GoodsID.ToString() + "'," +
                strType + "," + strUnit + ", '" + GoodsName.ToString() + "', '" +
                Amount.ToString() + "', '" + Price.ToString() + "', '" +
                Description.ToString() + "');";
           
            cmd.Connection = cnn;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
    }
};

Thank you
Hartigan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC