Parametized Queries In C#-Hard One.

Sep 2, 2007

Hi there,

I am using this stored procedure in sql.
I have 6 tables. One is called employees. This is what I need to be able to do. A user enters a new employee into a winform, picks a role, division, manager, technicalskill set and applications from the drop down lists and hits save. The employee table should be the only one updated and has these columns only.( firstname, lastname, dvisionid, managerid, roleid,techskillsid, and appID). At the moment what is happening is its saving the firstname, lastname correctly, but the rest of the ID columns are null. It is updating the other tables with the string entered but what I need is the emplyee table to update with the corresponding ids. Is this alot more complicated then i thought? If I try to replace the role with roleid etc, it will just tell me I can't convert string to int which is understandable. How do I do this?


CREATE PROCEDURE sp_InsertEmployee
@Firstname nvarchar(50),
@Lastname nvarchar(50),
@Role nvarchar(50),
@Manager nvarchar(50),
@Division nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO EMPLOYEES (FIRSTNAME, LASTNAME) VALUES (@FIRSTNAME, @LASTNAME)
INSERT INTO [ROLE] ([ROLE]) VALUES (@ROLE)
INSERT INTO MANAGER (MANAGER) VALUES (@MANAGER)
INSERT INTO DIVISION(DIVISION) VALUES (@DIVISION)
END
GO

My C# code is like this:

SqlCommand sqlC = new SqlCommand("sp_InsertEmployee", myConnection);

sqlC.CommandType = CommandType.StoredProcedure;

sqlC.Parameters.Add(new SqlParameter("@Firstname", SqlDbType.VarChar, 50, "Firstname"));

sqlC.Parameters.Add(new SqlParameter("@Lastname", SqlDbType.VarChar, 50, "Lastname"));
sqlC.Parameters.Add(new SqlParameter("@RoleID", SqlDbType.Int, 50, "RoleID"));

sqlC.Parameters.Add(new SqlParameter("@ManagerID", SqlDbType.Int, 50, "ManagerID"));
sqlC.Parameters.Add(new SqlParameter("@DivisionID", SqlDbType.Int, 50, "DivisionID"));

//sqlC.Parameters[0].Value = 4;
sqlC.Parameters[0].Value = FirstnameText.Text;
sqlC.Parameters[1].Value = Lastnametext.Text;
sqlC.Parameters[2].Value = RolecomboBoxTest.Text;
sqlC.Parameters[3].Value = ManagercomboBox1.Text;
sqlC.Parameters[4].Value = DivisioncomboBox2.Text;

int i = sqlC.ExecuteNonQuery();
//sqlC.ExecuteNonQuery();


Sorry for pasting so much.

View 2 Replies


ADVERTISEMENT

Creating Queries Is Hard! Help Needed!

Jan 22, 2008

I am using a poker application that imports all played hands into a PostgreSQL database. I'm trying to write some queries for that database so I can make good use of the data. I figure PostgreSQL and SQL server probably have similar language. And I know these forums are great. So I'm posting here for help.

This is a working code snippet that retreives three properties of a player:



Code Snippet

SELECT sum(totalhands) AS HANDS, sum(vpiphands) AS VPIPHANDS, sum(pfrhands) AS PFRHANDS
FROM compiledplayerresults WHERE compiledplayerresults_id in (
SELECT compiledplayerresults_id FROM compiledresults WHERE play
SELECT player_id FROM players WHERE playername='PLAYERNAME'));
This is all I can do with my skills right now. However I very much want to learn to query for more things:
- I'd like to be able to make a query for several players at the same time
- I'd like to be able to get the aggregate properties for all players who are not PLAYERNAME1 or PLAYERNAME2
- I'd like to be able to get the aggregate vpiphands property from all players whose totalhandsis > 100 and < 1000.

I hope you can help me with that. If you can, that will make me very happy and grateful! Thanks!

View 4 Replies View Related

Parametized Select

Aug 17, 2000

i've checked a number of places, including the archives, but haven't found any guidance. i have to read data from a sql7 database, as a join. normally, that's not a big deal, but the select (if i could actually write it this way) would look thus:
<pre>
select * from table1, table2, <table3 name>
where table1.id = table2.id and
<table3 name> = table2.table2name
</pre>

that is, a table name is found from another table's column. i know that the database folks do most of their processing using stored procedures, and i'm guessing that this is how they manage to do the select. but i can't find any references that describe the syntax to use.

any guidance is appreciated.

robert young

View 3 Replies View Related

Parametized Inserts In A Loop

Mar 12, 2006

Hi,
I have a for next loop that I am using to write some data into a table.
The problem I have is one of the fields is an @parameter
The relevant bit of VB.net code is:
Dim dbpm_theDateTime As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
           
            dbConnection.Open()
            For intCounter As Integer = 0 To ds.Tables(0).Rows.Count - 1
          
                querystring = "Insert into tblActionsToDo ([TheDT], [username]) VALUES (@theDateTime, '" & username & "’)â€?
           
                dbpm_theDateTime = New System.Data.SqlClient.SqlParameter
                dbpm_theDateTime.ParameterName = "@theDateTime"
                dbpm_theDateTime.Value = tmpstrDT
                dbpm_theDateTime.DbType = System.Data.DbType.DateTime
                dbCommand.Parameters.Add(dbpm_theDateTime)
               
                dbCommand.CommandText = querystring
                                
                rowsAffected = dbCommand.ExecuteNonQuery
               
               
            Next
The first time through the for next loop, everything works fine.  The next time though I get an error that @theDateTime has already been defined.  To be fair, it is true; but how do I get round this?  I've tried making the @parameter a string so that I can manipulate it as "@parameter" & intcounter, and thus have a uniquely-named varaible for every loop, but it doesn't work.
thanks for any pointers

View 1 Replies View Related

HARD TOP SQL PROBLEM PLEASE HELP

Apr 5, 2005

Hi,
I need to use a top and a join in the same sql. To get 10 top refnr from orders_refnr. That works fine to I use this:
SQL = "SELECT TOP 10 refnr, antal = COUNT(refnr) FROM orders_refnr INNER JOIN produkter ON (orders_refnr.refnr = produkter.referensnummer) GROUP BY refnr ORDER BY antal DESC"
But I need to be able to get information from more fields than the field refnr. How can I specify more fields? I need to get other fields from produkter.
Please helt I´m really stucked.

View 4 Replies View Related

Is This SQL Test Too Hard?

May 17, 2007

I have gotten some criticism from coworkers regarding this test and just wanted to see what you guys think. I realize the wording could use improvement and any criticism towards making it easier to understand is much appreciated.FWIW - I had to solve this problem on the job so I feel it is a real-world test that helps me understand how people think and if they try to find alternate solutions.Thanks!~~~~~~~~~~~~~~~~~~~~Given a table that has over 100,000 records…SUBSIDIARY=========PARENT_IDINTCHILD_IDINTULTIMATE_PARENT_IDINTCLEANUP_INDBIT…where each PARENT_ID can have multiple CHILD_ID values, but the PARENT_ID should not equal the CHILD_ID. After an initial data load, the ULTIMATE_PARENT_ID and CLEANUP_IND columns contain NULL values (see page 2 for sample data).ULTIMATE_PARENT_ID is defined as the topmost parent in the chain for the particular CHILD_ID record, so if the chain was only 2-level’s deep the ULTIMATE_PARENT_ID is the CHILD_ID’s PARENT_ID’s PARENT_ID.Please write an answer for all three questions below:A)Which of the following queries should you run first?B)Write an optimized query to identify the ULTIMATE_PARENT_ID for each CHILD_ID and set its value into the ULTIMATE_PARENT_ID column.C)Write a query to identify ALL of the circular references and mark each record that is a circular reference by updating the CLEANUP_IND column to 1.~~~~~~~~~ Page 2 ~~~~~~~~~ Sample Data, remember though this table has over 100,000 records and the parent-child chain can go n-levels deep – where n is not known.PARENT_IDCHILD_IDULTIMATE_PARENT_IDCLEANUP_IND1024512NULLNULL362300NULLNULL887541NULLNULL10221024NULLNULL546887NULLNULL5122305NULLNULL112967NULLNULL697123NULLNULL901452NULLNULL2300666NULLNULL334445NULLNULL512903NULLNULL884554NULLNULL313313NULLNULL554884NULLNULL112119NULLNULL967555NULLNULL2305333NULLNULL33336NULLNULL541546NULLNULL10301020NULLNULL112999NULLNULL

View 14 Replies View Related

Hard Query

Feb 13, 2006

hello

i have a proplem in query

i have 2 tables in my sql db one named stuednt include fields(id,name)

and one table named stu_cources include fields(id,course_name)

ok

i want to query the student that have courses EX. mcse

the result that i want from 2 tables

ID | NAME | Coures_NAME

in MSHFLEXGRID1



any one help me plz ...

View 4 Replies View Related

Reconfigure NT Hard Drive

Nov 14, 2000

hi, I have NT server which has drive c: 500 MB and drive d has 44 GB.

I know that the person who set up this server did not give enough space to the c drive, here is the problem. I am running sql server 7.0 which has 30 GB of data in the d drive. I need to reconfigure the NT hard drive so I can allocate 2 GB for C drive and 42 GB for D drive.


What is the best, safe method to accomplish this task.

Ahmed

View 3 Replies View Related

Hard Drive Failure

Sep 27, 1999

After experiencing a hard drive failure i have reinstaled MSSQL7 on one drive and have a database which I need to recover on separate physical drive. How can I go about doing this?

View 1 Replies View Related

Hard Drive Status

Jul 17, 2003

Hi,
I have ran
1. xp_fixeddrives and got the result
drive MB free
----- -----------
C 1708
D 16311
2. I ran Backup Wizard in EM and able to see only above drives

3. But if ran backup in EM able to see more than 10 Drives(like C,D,H,I,J,M,N and etc).
Why I can able to see those difference?.
How do I find out exactly how many drives are there in this server without directly going to that server?.
I appreciated your valuable answere.
Thanks,
Ravi

View 8 Replies View Related

Monitor Hard Drives

Jul 30, 2001

Hi, I'm looking for a way to check the free space left on the hard drives and then if needed send an alert to notify when we need to free up some space. I played around with the performance monitor and realized I could do it that way but I think you would have to leave the performance monitor running all the time and I'm not sure if I want to do that. I also read about the xp_fixeddrives proc that displays how much free space is available but then I don't know what to do from there? Does anyone have any recommendations for the best way to do this.

View 3 Replies View Related

SQL Sorting Question (hard One)

Feb 19, 2007

Right, I have this database that I need to sort, I'll give you an example:

ID Name Value
2312 Sega 200
5678 Blizzard 215
3412 Bullfrog 210
6798 Nintendo 195

Now, what I need to do is to sort it, perform calculations on and I need the list to be sorted with a predefined post as the top result, say like this one time:

ID Name Value
3412 Bullfrog 200
2312 Sega 210
5678 Alizzard 215
6798 Nintendo 195

as you can see sorting it alphabetically would lead to

5678 Alizzard 215
3412 Bullfrog 210
6798 Nintendo 195
2312 Sega 200

(or the other way around if you play with asc/desc)
by id would be

2312 Sega 200
3412 Bullfrog 210
5678 Alizzard 215
6798 Nintendo 195

There aren't any top or bottom values sort of speak for the posts I want to be on top, so...how to sort this like this?

3412 Bullfrog 200
2312 Sega 210
5678 Alizzard 215
6798 Nintendo 195

the order after the top one is irrelevant.

Now...I know I could sort this by doing something like

"Select * FROM blablabla WHERE Name = 'Bullfrog'"

and then doing "Select * FROM blablabla" and then just bypassing that post in asp/php code or whatever, but that would be a pain for me to do as I have to perform some massive calculations and the code would be alot larger then needed be

Its a brain teaser allright...can you help me out?

View 5 Replies View Related

The Hard Drive Configuration

Apr 7, 2004

Hello, everyone:

Does any one have an idea for hard drive configuration on SQL Server 2K? How to determine the RAID level for datafile and log file? Thanks

ZYT

View 2 Replies View Related

Formatting The Hard Drive

May 18, 2004

I was wondering if anyone played around with changing the allocation unit size when formatting the hard drive the SQL server is running on. I would think that setting it higher to account for the larger size of the database files would help, but I'm not sure.

Anyone have any thoughts?

View 3 Replies View Related

Multiple Hard Disk

May 29, 2007

Hello!

I have 2 harddisk in my computer and I have SQL 2005 Express on 1 of them (let's say C:), however, my C: is going to be full soon! Once it is full, is it possible to create a table on my other harddisk which the server can recognise?

Thanks!
OB

View 4 Replies View Related

Learning About Indexes The Hard Way

Oct 18, 2006

Hello, I am experimenting with indexes and hope people can shed lighton some of my problems.I am using SLQ 2000 on Win 2000 Server. Using the following query fordiscussion;--------------------------------SELECT TOP 1000000E.EUN_Numeric, -- Primary KeyE.EUN_CODE, -- VarCharE.[timestamp] --,--E.Model -- Computed column (substring of EUN_CODE)FROM dbo.Z1_EUNCHK E--WHERE E.[timestamp]DATEADD ( wk , -48, getdate() ) AND-- E.[timestamp]< DATEADD ( wk , -4, getdate() )ORDER BY E.[timestamp] DESC-----------------------------------Problem 1) If I set up a single Index on the TimeStamp (plus the PK onEUN_Numeric) then there is not improvement in performance.It is only when I set up an Index on the Timestamp,EUN_Numeric,EUN_Codethen I get a good improvement. This is also thecase with the "where" clause added. I am using query analyser. Theimprovement is 14 secs to 3 secs (mainly with the removal of the sortprocess)Why?My expectation is that if my query uses [timestamp] column then surelyan index only on this is adequate.Problem 2) Introducing the simple computed column into the query takesthe time to 15 secs (with Sort processes involved).Why does revert back to sorting process when previous the index wasused ?Regards JC......

View 6 Replies View Related

Mirroring Hard Drives

Jul 16, 2007

I have a 75 GB hard drive and a 300 GB. I want to mirror the 75 to the 300 and use the extra space as data storage. Is this possible if I partition the 300 and then mirror the hard drives.

Thanks

View 5 Replies View Related

How Hard Would This Be - Automating With Vbscript ?

Oct 5, 2007

How can I do this with vbscript, or C# ?
- Copy backup files down from a network share, into the data directory of my local sql 2005 instance
- perform a restore using the files copied from above
- Execute a dts package


More info:
Our databases are scripted and exist on the typical development, and testing enviroments. So as I get ready to start a new application, I want my local sql instance to be updated based on structure changes as well as data. So I have to apply the changes from the scripted sources and pull over the data. I would naturally like to automate this.

ideas / suggestions welcome

View 6 Replies View Related

Setting Up The Hard Disks

Nov 8, 2007

I have a new server.

It was shipped with a 76 gig drive setup in RAID 1 (2 disk) and a 400 gig drive setup in RAID 5 (4 disk).

I would like to determine what is the best way to setup up the partitions. What size and what should be placed on each.

Like the C: Drive...Should I just put Windows on there and nothing else? Do I stand to gain something from not using part of that 76 gigs as a D: drive for my apps?

View 1 Replies View Related

Hard Coded Parameters

Feb 8, 2007



Is it possible to force parameters into the reports so enabling me to force a user id value into every report that is picked up from the list. The user ID is a system value and I don't want end users having any knowledge of it?



Cheers



Darren

View 7 Replies View Related

SQL Connection Hard Coded To Database

Jun 6, 2007

Me.SqlConnection1.ConnectionString = "workstation id=""XXXXXXXX"";packet size=4096;user id=XX;data source=""XXXXXXX"";persi" & _
"st security info=True;initial catalog=manufacturing;password=XXXXX"
 
What excatly is this statement doing it looks to be creating a trusted connection to a certain workstation?

View 3 Replies View Related

Hard Task To Retrieve A Value From A Record?!

Feb 12, 2008

Hi!I'm desperating here!!! Two questions:1º  Is line 13 realy selecting all the records with the username samurai (in this case)?!2º How do I fill the Boolean SeExiste var with a value from the record?1 Dim UserIDParameters As New Parameter
2
3 UserIDParameters.Name = "ProdUserID"
4
5 UserIDParameters.DefaultValue = "samurai"
6
7 Dim LoginSource As New SqlDataSource()
8
9 LoginSource.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ToString()
10
11 LoginSource.SelectCommandType = SqlDataSourceCommandType.Text
12
13 LoginSource.SelectCommand = "SELECT FROM aspnet_Users (FirstTime) VALUES (@UserIDParameters) "
14
15 Dim SeExiste As Boolean
16
17 SeExiste = LoginSource.SelectParameters("FirstTime").DefaultValue
 I'm a newbye and despite this simple thing that in normal ASP is very easy to do!!! Please help me!Thanks in advance!  

View 4 Replies View Related

Working With A Hard Coded Primary Key

Feb 24, 2004

Hi there,

The postage and packing scheme being used at the site I'm working on depends on the customer's location.

If they're in the UK they get once scheme and if they're in Ireland they get another. Furthermore, if they're anywhere else they get another scheme.

A customer's country is indicated by a 'countryID' stored in the main customer row in the database. (This ID references a country in the Countries table.)

Thus, I was wondering if it is acceptable to hard code the country pk of the UK and Ireland into the formular which works out the postage and packing?

At present, for a similar issue, I've even hard coded the the pk of UK and Ireland into some Javascript running at the client.

Is it fair design to work with a hard coded pk like this?

Cheers,

View 1 Replies View Related

Soft And Hard Returns Don't Show Up

Jun 23, 2005

hi,,,here is the issueon the site there is a multiline text box.people type in muliple lines including soft line breaks(soft return (shift+enter)) and hard line breaks (hard return(enter)).  the data gets stored in the SQL server 2000 database.  In enterprise manager I can see the returns (the line breaks), but when the same data gets posted back to the page it loose those soft and hard returns,whats going onhelp

View 1 Replies View Related

Is It That Hard To Deploy SQL Server Express?

Mar 30, 2006

I'm on day 3 of troubleshooting.... still no luck!Very simple application.  Extract data from the database and populate the GridView.Following error message:Server Error in '/WebSite3' Application.

An
attempt to attach an auto-named database for file
C:Webspaceigiriabcabc.comwwwWebSite3App_DataDatabase.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share.-------------------------------------------------Look familar? so i Googled it and tried everything, from removing the User Instance = true in the web.config and even adding intial Catalog = Database and it didnt work.Instead i was greeted with a Newer Error msg:Server Error in '/WebSite3' Application.

Could not open new database 'Database'. CREATE DATABASE is aborted.Could
not attach file
'C:Webspaceigiriabcabc.comwwwWebSite3App_DataDatabase.mdf'
as database 'Database'.File activation failure. The physical file
name "D:-- Work Documents --WorkezabcWebSite3App_DataDatabase_log.LDF" may be incorrect.The log cannot be rebuilt when the primary file is read-only.Next i have no idea why it's pointing back to my location directory hence that could be the issue but i'll leave it to you experts for your valueable input.It's uploaded onto a web server running ASP 2.0 and MS SQL Server 2005 i thinkFeel free to ask if you need additional informationThanks for reading!

View 9 Replies View Related

Using Variables Instead Of Hard Coded Values

Dec 12, 2001

I thought a stored procedure was taking much too long to complete. So, I moved the main query to Query Analyzer and found that when I substituted actual values for variables that my SELECT statement ran in seconds. Just to test, I created DECLARE statements, set the variables equal to the same values, re-ran the SELECT statement and it took over a minute. Even the Execution Plan was much different. Any suggestions?

View 4 Replies View Related

Sa Account And Hard Coded Application

Mar 27, 2001

Hello I was hoping somebody out there could help me …..

We have a hard-coded application which uses the Sa account with no password. We want to add password to Sa – but when we do get users/DBAs calling us saying the application does not work.

How can we add password to Sa and get the application to work - unfortunately we do not have scripts for the application or know of the whereabouts of the developers.

Any suggestions/ideas – will be greatly appreciated

Cheers

Khalid

View 2 Replies View Related

SQL Server And Hard Ware Issue

Aug 7, 2001

Could some of the technical gurus we have please help me to solve this problem.!!!

We lost power, and when the generator came on our system crashed and the data and the hardware was gone. We initialized the disk and we lost our backups. There is no tape backup in the company. Thanks for your help.

View 2 Replies View Related

Hard Drive Setup Question

Feb 2, 2007

Hi guys,

I have a general question. Would SQL server have slower performance if you placed the ldf or mdf files on a dynamic drive setup or should it always be basic? I noticed that a server had 2 dynamic drives and the log files and mdf files are located on these drives. Usually I see all the drives as basic not dynamic. Does this even matter?

thanks

View 1 Replies View Related

Backup To Non-local Hard Drive

Oct 19, 1998

I want to perform backups to a network drive. I need to know if I can access the backup drive via UNC. I have not been able to get it to work and, for now, I would just like to know if what I am trying to do SHOULD work.

For example I want to backup to device mdtnts_prod02LM2BackupNameBack.DAT.

Thanks,Bob

View 1 Replies View Related

Identifying What Is Using My Hard Disk Cycles

Jul 25, 2001

Hello,

I monitor a few "perfmon" counters which includes under the "system" object, "bytes transmitted/sec" and "file read bytes/sec". Every once in awhile, these counters will skyrocket, which can also be verified by the hard drive lights flickering like mad.

The only software installed on the machine is SQL Server 2K.

I was wondering if anyone knew how I could monitor within SQL 2K what process or user is using all of these cycles. If anyone could shed some light on this it would be greatly appreciated. Specifically, I would like to find out which database/query is doing this to minimize in the future as this affects all of the other connections.

Thanks in advance,
Brent.

View 1 Replies View Related

Need DTS VB Script To Extract A Hard Return.

Nov 5, 2001

Hi,

Does anyone know if I can strip out a carriage return in a varchar column. So far the only way I feel that this could be done is to write VB Script in DTS.. Could anyone get me started on the VB script? IF so reply or email me . Thanks and this could be a billable call.

I will pay for this info.

4046323231 cell

View 2 Replies View Related

Export Data Onto Hard Disk

Mar 10, 2004

Hello People,

I have began to store binary data in my database, for example word documents, PDF's....etc.

But now my database file is growing beyond what I want, and I need to move all of the files out of the DB onto normal hard disk space.

Is there anyway, say by using a bulk copy command, that I can write all the contents of the table into a folder on my hard disk...???

My database table consists of ID(int), Filename(varchar), Filetype(varchar), Filesize(varchar), Filebody(image)

Any help would be extremely appreciated.....

Many Thanks,

Alan...

View 2 Replies View Related







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