SQL Paramters

Nov 4, 2007

I am in a SQL Class and I am starting to learn about SQL Parameters in conjunction with using them from a C# program. I have a couple of questions.

1. When I include an Output parameter in the list or paramters that I send, SQL always is returning a message indicating that the parameter was missing, when I know in fact that I am passing the paramter (@RtnMsg)

2. When I remove any reference to "@RtnMsg", which it can not find, and execute the stored procedure it always returns a -1 and never inserts the record.

Here is my code for the stored procedure....


ALTER procedure [dbo].[Insert_Biblio]

@ISBN as char(11),

@CALL_NO as char(20),

@DEWEY_NO as char(20),

@AUTHOR as char(5),

@TITLE as char(100),

@AUTHOR_BORN as int,

@AUTHOR_DIED as int,

@PUBLISHER as char(30),

@YEAR_PUBLISHED as int,

@BOOK_INFO as char(49),

@BOOK_HEIGHT as int,

@BIBLIO_INFO as char(100),

@COST as money,

@TOPIC_1 as char(30),

@TOPIC_2 as char(30),

@RtnMsg as varchar(50) output

as

declare @Book_ID as char(5);

begin

Set @RtnMsg = 'Insert Successful'

return 0

select @Book_ID = max(book_ID) + 1

from collection

insert into biblio

(BOOK_ID,ISBN, CALL_NO, DEWEY_NO, AUTHOR, TITLE,

AUTHOR_BORN, AUTHOR_DIED, PUBLISHER, YEAR_PUBLISHED,

BOOK_INFO, BOOK_HEIGHT, BIBLIO_INFO, COST,

TOPIC_1, TOPIC_2)

values (@BOOK_ID,@ISBN, @CALL_NO, @DEWEY_NO,

@AUTHOR, @TITLE, @AUTHOR_BORN,

@AUTHOR_DIED, @PUBLISHER, @YEAR_PUBLISHED,

@BOOK_INFO, @BOOK_HEIGHT, @BIBLIO_INFO,

@COST, @TOPIC_1, @TOPIC_2)

return 0

end



Here is the C# program code (this version is the one where SQL tells me @RtnMsg is missint.


SqlParameter[] parms = new SqlParameter[16];

parms[0] = new SqlParameter("@ISBN", SqlDbType.Char, 11);

parms[0].Value = (txtISBN.Text.Length == 0 ? (object)DBNull.Value : txtISBN.Text);

parms[1] = new SqlParameter("@CALL_NO", SqlDbType.Char, 20);

parms[1].Value = (txtCallNbr.Text.Length == 0 ? (object)DBNull.Value : txtCallNbr.Text);

parms[2] = new SqlParameter("@DEWEY_NO", SqlDbType.Char, 20);

parms[2].Value = (txtDewerNbr.Text.Length == 0 ? (object)DBNull.Value : txtDewerNbr.Text);

parms[3] = new SqlParameter("@AUTHOR", SqlDbType.Char, 5);

parms[3].Value = (txtAuthor.Text.Length == 0 ? (object)DBNull.Value : txtAuthor.Text);

parms[4] = new SqlParameter("@TITLE", SqlDbType.Char, 100);

parms[4].Value = (txtTitle.Text.Length == 0 ? (object)DBNull.Value : txtTitle.Text);

parms[5] = new SqlParameter("@AUTHOR_BORN", SqlDbType.Int);

parms[5].Value = (txtAuthorDOB.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtAuthorDOB.Text));

parms = new SqlParameter("@AUTHOR_DIED", SqlDbType.Int);

parms.Value = (txtAuthorDOD.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtAuthorDOD.Text) );

parms[7] = new SqlParameter("@PUBLISHER", SqlDbType.Char, 30);

parms[7].Value = (txtPublisher.Text.Length == 0 ? (object)DBNull.Value : txtPublisher.Text);

parms = new SqlParameter("@YEAR_PUBLISHED", SqlDbType.Int);

parms.Value = (txtYearPublished.Text.Length == 0 ? (object) DBNull.Value : Convert.ToInt32(txtYearPublished.Text) );

parms[9] = new SqlParameter("@BOOK_INFO", SqlDbType.Char, 49);

parms[9].Value = (txtBookInfo.Text.Length == 0 ? (object)DBNull.Value : txtBookInfo.Text);

parms[10] = new SqlParameter("@BOOK_HEIGHT", SqlDbType.Int);

parms[10].Value = (txtBookHeight.Text.Length == 0 ? (object)DBNull.Value : Convert.ToInt32(txtBookHeight.Text));

parms[11] = new SqlParameter("@BIBLIO_INFO", SqlDbType.Char, 100);

parms[11].Value = (txtBiblioInfo.Text.Length == 0 ? (object)DBNull.Value : txtBiblioInfo.Text);

parms[12] = new SqlParameter("@COST", SqlDbType.Money);

parms[12].Value = (txtCost.Text.Length == 0 ? (object)DBNull.Value : Convert.ToDouble(txtCost.Text));

parms[13] = new SqlParameter("@TOPIC_1", SqlDbType.Char, 30);

parms[13].Value = (txtTopic1.Text.Length == 0 ? (object)DBNull.Value : txtTopic1.Text);

parms[14] = new SqlParameter("@TOPIC_2", SqlDbType.Char, 30);

parms[14].Value = (txtTopic2.Text.Length == 0 ? (object)DBNull.Value : txtTopic2.Text);

parms[15] = new SqlParameter("@RtnMsg", SqlDbType.VarChar, 50);

parms[15].Direction = ParameterDirection.Output;

foreach(SqlParameter parm in parms)

{

if (parm.ParameterName != "@ReturnValue")

{ parm.Direction = ParameterDirection.Input; }

}

string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["CIS277ConnectionString"].ConnectionString;

SqlConnection cn = new SqlConnection(conStr);

SqlCommand cmd = new SqlCommand("dbo.Insert_Biblio", cn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddRange(parms);



cn.Open();

int rtnCode = cmd.ExecuteNonQuery();

View 1 Replies


ADVERTISEMENT

NULL As The Default Value Of SP Paramters

Jun 4, 2006

Hello,

View 3 Replies View Related

Finding Paramters With Defaults

Jan 12, 2000

Does anyone have a way of finding all parameters with default values, for any stored procedure in a database?

aTdHvAaNnKcSe!

View 1 Replies View Related

Variable Paramters To Functions

Jul 20, 2005

From previous postings I have read it seems that I cannot create afunction that accepts a variable list of parameters. Seems that SQLServer does not support this.A few questions:Is this true?What is a workaround?Then how does the function COALESCE do it?Cut and pasted from online books:SyntaxCOALESCE ( expression [ ,...n ] )ArgumentsexpressionIs an expression of any type.nIs a placeholder indicating that multiple expressions can bespecified. All expressions must be of the same type or must beimplicitly convertible to the same type.

View 3 Replies View Related

Really Easy One... How Do I Set Multi-value Paramters?

Nov 15, 2007

What is the proper syntax for the SET transact-sql for mult-value parameters? Is this even possible?





Code Block

declare @Name char(55);

set @Name = 'name1';


select *

from table1

where name in (@Name)

How do I write the SET line so that it will behave like this:

where name in ('name1','name2','name3')

I'm sure this is an easy one, I'm currently looking it up, but thought someone might be able to answer this for me quick.

Thanks much!

View 5 Replies View Related

Full Text Searching With Paramters

Feb 28, 2008

i have a query in SQL Server 2005 that uses a parameter like so:ALTER Procedure [dbo].[p_FullTextEquipmentSearch]

@search as nvarchar(50),

as

SELECT * FROM EquipmentView

where contains(*, @search);

 what i want to so is add more parameters to the query so that the user can choose either 1 or many for the search can anyone help me on this

View 2 Replies View Related

Changes In Paramters In RS2005 Compare To RS2000

Nov 27, 2007

Hi there,

I've got a RS2000 report from Analysis services 2000. This report is working fine but after the upgrade to SQL2K5, i'm having issues with changes to parameters.

Basically i'm passing DateQuarter, CustomersLevel as parameters to the following mdx script. I've tried to change mdx script in RS2005 but no luck yet. I don't much about the parameter level changes in sql2k5. So can anyone suggest what is wrong in the script.




Code Block
RS2000

="with " &
"member [Measures].[Ex Price] as 'coalesceempty([Measures].[Ex Price After Trade Discount - Detail],0.00)' " &
"set [Rolling Quarters] as '" + Parameters!DateQuarter.value +".lag(4):" + Parameters!DateQuarter.value + "'" &
"SELECT " &
"{[Measures].[Ex Price]} ON COLUMNS , " &
"filter({CrossJoin([Items by Class].[Item Class Description].members, [Rolling Quarters])}, [Measures].[Ex Price] > 0) on Rows " &
"FROM Sales " &
"WHERE (" & Parameters!CustomersLevel.Value & ")"

RS2005

with
member [Measures].[Ex Price] as 'coalesceempty([Measures].[Ex Price After Trade Discount - Detail],0.00)'
set [Rolling Quarters] as '@DateQuarter' +'.lag(4):' + '@DateQuarter'
SELECT
{[Measures].[Ex Price]} ON COLUMNS ,
filter({CrossJoin([Items by Class].[Item Class Description].members, [Rolling Quarters])}, [Measures].[Ex Price] > 0) on Rows
FROM Sales
WHERE STRTOSET(@CustomersLevel)


Thanks in advance,

Vivek

View 4 Replies View Related

Problem With Non Multi-value Paramters After Installing SP2 CTP

Nov 14, 2006

Hello,

I just installed the new SQL 2005 sp2 CTP on my stand alone report server. Now whenever a parmeter is not multi-value I get


One or more data sources is missing credentials


when clicking off the parameter. If I set the parameter to multi-value it works fine but confuses the users.




Does anyone know how to debug this or if a fix is available ? Yes it was working before I installed the service pack.

View 3 Replies View Related

How Does MS ReportingServices Derive Oracle Paramters

Apr 28, 2008

We are using MS Reporting Services to generate Xmls for corporate billing statements. Our DBAs found that MS ReportingServices are querying Oracle Catalogue before executing stored procedures in RDLs to get Oracle parameter information. Is there a way to eliminate the trip to database before executing the stored procedures?


Hongmei

View 1 Replies View Related

Problem In Concatinating Two Paramters To Update One Column

Sep 20, 2007

 Using gridview to display the data and sql server 2000 I have
a column in the database say departtime of datetime datatype that
cntains the date and time resp(09/19/2007 9:00 PM). I am separating the
date and time parts to display in two different textboxes say
txt1(09/19/2007) contaons date and txt2(9:00 PM) contains time by using
the convert in sqldatasource. Now i need to update the column in the
database and i am using Updatecommand with parameters in aspx  lke
updatecommand = "Update table set departtime = @departtime" . How  can
i  update my column as datetime by getting the data from 2 texboxes as
now i have 2 textboxes displaying data for single column means if user
edit the data in txt1 as(10/19/2007) then on click of update i need to
populate the column daparttime as (10/19/2007 9:00 PM).Please let me know if you have any questions.

View 1 Replies View Related

Stored Procedure With Unknown Numer Of Paramters, How?

Mar 29, 2006

I have one table with categoriestblCategoriescat_id | cat_name-----------------1 | cat 12 | cat 23 | cat 34 | cat 45 | cat 56 | cat 6and one table with projects which relates to tblCategoriestblProjectsproj_id | proj_name | cat_id----------------------------1 | proj 1 | 22 | proj 2 | 23 | proj 3 | 34 | proj 4 | 2How would you create stored procedure for searching some string infiled proj_name but within multiple categoriesfor exampleCREATE PROCEDURE [spSearch](@SEARCH_STRING nvarchar(200),@CAT_ID int)ASBEGINSELECT proj_idFROM tblProjectsWHERE (proj_name LIKE '%' + @SEARCH_STRING + '%') AND (cat_id =@CAT_ID)ENDBut that one works only with one categorie and i need to search for oneor more categories at once, does anyone have a solution? Is theresomething like ellipsis (...) in C++ for MSSQL?

View 7 Replies View Related

ADO Connection.Open Hangs If Paramters Are Wrong

Nov 5, 2007

Hi
Im writing a program that stores data to SQL server 2005.
Program writen on VC++ 2003.
Code is very simple and it works ok if server runs and parameters are ok.


try
{

HRESULT hr = m_Connection.CreateInstance(__uuidof(ADODB::Connection));

String ConnectionStr;

ConnectionStr.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=MyDB;User Id=%s;Password=%s;"),m_Server.c_str(),m_Username.c_str(),m_Password.c_str());

_bstr_t bstrConnection(ConnectionStr.c_str());




m_Connection->CursorLocation = ADODB::adUseClient;

hr = m_Connection->Open(bstrConnection, L"", L"", ADODB::adConnectUnspecified);
}
catch(_com_error &e)

{

_bstr_t Description = e.Description();
}

But!
if i give wrong paramterer for Data Source , it may happen if user configures it and misprints it, or if server goes offline for some reason, program just hangs on m_Connection->Open and never gives exception as it should.
Any ideas what wrong?
Thanks.

View 4 Replies View Related

Best Settings And Paramters For Update Data Optimization Information

Nov 16, 2007

In SQL 2000, working with Maintenance plan wizard, what would be best settings and values should i choose in "Update Data Optimization information" window,

Thanks,

View 6 Replies View Related

Custom Parameter For Select Paramters - How To Use The Value Of Another Field As The Paramter Default.

Mar 5, 2008

SELECT     ArticleID, ArticleTitle, ArticleDate, Published, PublishDate, PublishEndDateFROM         UserArticlesWHERE     (ArticleDate >= PublishDate) AND (ArticleDate <= PublishEndDate)
When I use the above on a GridView I get nothing.  Using SQL manager it works great.
I don't know how to pass the value of the ArticleDate field as a default parameter or I think that's what I don't know how to do.
I am trying to create a app that I can set the dates an article will appear on a page and then go away depending on the date.
 Thanks for any help!
 

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved