Monday, March 26, 2012
Help With Another Query
I have a table simular to the following:
ID = int (Key)
Name= VarChar
Department = nChar
Example Data
ID Name Department
1 Chuck A
2 Mark A
3 Chuck T
4 Chuck S
5 Mark S
I am looking for a query that will Return
Name All Departments
Chuck ATS
Mark AS
Without duplicate Names.
Thanks,
ChuckHi
I'd prefer doing such things on the client side
create table w
(
id int,
t varchar(50) NOT NULL
)
insert into w values (1,'abc')
insert into w values (1,'def')
insert into w values (1,'ghi')
insert into w values (2,'ABC')
insert into w values (2,'DEF')
select * from w
create function dbo.fn_my ( @.id int)
returns varchar(100)
as
begin
declare @.w varchar(100)
set @.w=''
select @.w=@.w+t+',' from w where id=@.id
return @.w
end
select id,
dbo.fn_my (dd.id)
from
(
select distinct id from w
)
as dd
drop function dbo.fn_my
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:OrLlfeQXHHA.996@.TK2MSFTNGP02.phx.gbl...
> Hello and Thank You for your previous help,
> I have a table simular to the following:
> ID = int (Key)
> Name= VarChar
> Department = nChar
> Example Data
> ID Name Department
> 1 Chuck A
> 2 Mark A
> 3 Chuck T
> 4 Chuck S
> 5 Mark S
> I am looking for a query that will Return
> Name All Departments
> Chuck ATS
> Mark AS
> Without duplicate Names.
> Thanks,
> Chuck
>
Friday, March 23, 2012
help with a stored procedure
here is my sp
create proc [login]
(
@.email as varchar(200)
@.password as varchar(200)
)
as
begin
select customerid from customerlogin
where email = @.email
and password = @.password
End
print 'Welcome'
print (@.email)
End
This works fine, but if the email is wrong, what do I need to add to this to print that the email is wrong and not print 'welcome email'
Help, please.....
Hello,
I think what you want is:
create proc [login]
(
@.email as varchar(200)
@.password as varchar(200)
)
as
IF EXISTS (select customerid from customerlogin where email = @.email and password = @.password)
BEGIN
print 'Welcome'
print (@.email)
END
ELSE
BEGIN
print 'Bad login!'
print (@.email)
END
GO
As a side note, best practice is to NOT pass the users' password, but rather store a hash of the password and then when the user attempts to login, you simply create a hash of the entered password and compare it with the hashed value stored in the db.
Cheers
Rob
|||create procedure sp_login
@.email as varchar(200)
@.password as varchar(200)
AS
Select CASE WHEN ((Select COUNT(*) from customerlogin where email = @.email and password = @.password) = 0)
THEN Print 'Invalid Login'
ELSE Print 'Welcome ' + @.email
END AS [EmailTest]
Adamus
Wednesday, March 21, 2012
Help with a query
Im using a query like this:
select A.AfectadoApellidos as Apellido, A.AfectadoName,
A.AfectadoDNI,(Convert(varchar,TA. TipoAccionBreve)+Convert(varchar,Empresa
s.
EmpresaBreve)+Convert(varchar,E.ExpedienteIncidenciaID)) as Codigos
from Expedientes E
inner join Afectados A on E.AfectadoID=A.AfectadoID
inner join Empresas on E.EmpresaID=Empresas.EmpresaID
inner join TiposAccion TA on E.TipoAccionID=TA.TipoAccionID
group by A.AfectadoApellidos,
A.AfectadoName,A.AfectadoDNI,E.ExpedienteIncidenciaID,Empresas.EmpresaBreve,
TA.TipoAccionBreve
and im getting this result:
Apellido AfectadoName AfectadoDNI Codigos
-- -- -- --
Surname1 Name1 DNI1 CodeAAA
Surname2 Name2 DNI2 CodeBBB
Surname2 Name2 DNI2 CodeCCC
I would like to get anything like this
Apellido AfectadoName AfectadoDNI Codigos
-- -- -- --
Surname1 Name1 DNI1 CodeAAA
Surname2 Name2 DNI2 CodeBBB--CodeCCC
How could i get only a row for the name 2 surname 2?
--
Thanks a lot.
Regards.
JosemaCheck this.. For the concat string stuff...
[url]http://omnibuzz-sql.blogspot.com/2006/06/concatenate-values-in-column-in-sql.html[
/url]
-Omnibuzz (The SQL GC)
"Josema" wrote:
> Hi to all,
> Im using a query like this:
> select A.AfectadoApellidos as Apellido, A.AfectadoName,
> A.AfectadoDNI,(Convert(varchar,TA. TipoAccionBreve)+Convert(varchar,Empresa
s.EmpresaBreve)+Convert(varchar,E.ExpedienteIncidenciaID)) as Codigos
> from Expedientes E
> inner join Afectados A on E.AfectadoID=A.AfectadoID
> inner join Empresas on E.EmpresaID=Empresas.EmpresaID
> inner join TiposAccion TA on E.TipoAccionID=TA.TipoAccionID
> group by A.AfectadoApellidos,
> A.AfectadoName,A.AfectadoDNI,E.ExpedienteIncidenciaID,Empresas.EmpresaBrev
e,
> TA.TipoAccionBreve
>
> and im getting this result:
> Apellido AfectadoName AfectadoDNI Codigos
> -- -- -- --
> Surname1 Name1 DNI1 CodeAAA
> Surname2 Name2 DNI2 CodeBBB
> Surname2 Name2 DNI2 CodeCCC
>
> I would like to get anything like this
> Apellido AfectadoName AfectadoDNI Codigos
> -- -- -- --
> Surname1 Name1 DNI1 CodeAAA
> Surname2 Name2 DNI2 CodeBBB--CodeCCC
>
> How could i get only a row for the name 2 surname 2?
> --
> Thanks a lot.
> Regards.
> Josema|||If you don't need the concat and any row is fine, then you may use this..
select A.AfectadoApellidos as Apellido, A.AfectadoName,
A.AfectadoDNI,min(Convert(varchar,TA.TipoAccionBreve)+Convert(varchar,Empres
as.EmpresaBreve)+Convert(varchar,E.ExpedienteIncidenciaID)) as Codigos
from Expedientes E
inner join Afectados A on E.AfectadoID=A.AfectadoID
inner join Empresas on E.EmpresaID=Empresas.EmpresaID
inner join TiposAccion TA on E.TipoAccionID=TA.TipoAccionID
group by A.AfectadoApellidos, A.AfectadoName,A.AfectadoDNI
Hope this helps.
--
-Omnibuzz (The SQL GC)
http://omnibuzz-sql.blogspot.com/
Help with a query
Any help with this query is greatly appreciated...
DECLARE @.input TABLE
(NodeId VARCHAR(10),
IsChecked CHAR(1))
DECLARE @.Actual TABLE
(AndSetId INT,
NodeId VARCHAR(10),
IsChecked CHAR(1))
INSERT INTO @.Input VALUES ('a', 'T')
INSERT INTO @.Input VALUES ('b', 'T')
INSERT INTO @.Input VALUES ('c', 'F')
INSERT INTO @.Input VALUES ('d', 'F')
INSERT INTO @.Input VALUES ('e', 'T')
INSERT INTO @.Actual VALUES (1, 'a', 'T')
INSERT INTO @.Actual VALUES (1, 'b', 'T')
INSERT INTO @.Actual VALUES (1, 'c', 'F')
INSERT INTO @.Actual VALUES (2, 'c', 'F')
INSERT INTO @.Actual VALUES (2, 'd', 'F')
INSERT INTO @.Actual VALUES (3, 'd', 'F')
INSERT INTO @.Actual VALUES (5, 'd', 'F')
INSERT INTO @.Actual VALUES (5, 'e', 'F')
INSERT INTO @.Actual VALUES (6, 'f', 'F')
INSERT INTO @.Actual VALUES (7, 'g', 'F')
-- We should get back 1, 2, 3, 4. We should not get back 5, 6, 7Did your instructor include the rules (the logic) behind this, or only give you the two inputs and the output that they expected? Have you recently covered anything like this in class?
-PatP|||Pat-
My apologies for not elaborating enough, what I was looking for.
Get all AndSetIds from @.Actual where
if NodeId is present in @.input then the isChecked should match.
eg: AndSetId 1
It has 3 records. And the records match with the records
in Input.
So 1 should be returned.
Where as let us look at AndSet 5.
It has NodeId 'e' as 'F' where as the input has 'e' as 'T'
So 5 should not be returned.
INSERT INTO @.Input VALUES ('a', 'T')
INSERT INTO @.Input VALUES ('b', 'T')
INSERT INTO @.Input VALUES ('c', 'F')
INSERT INTO @.Input VALUES ('d', 'F')
INSERT INTO @.Input VALUES ('e', 'T')
INSERT INTO @.Actual VALUES (1, 'a', 'T')
INSERT INTO @.Actual VALUES (1, 'b', 'T')
INSERT INTO @.Actual VALUES (1, 'c', 'F')
INSERT INTO @.Actual VALUES (2, 'c', 'F')
INSERT INTO @.Actual VALUES (2, 'd', 'F')
INSERT INTO @.Actual VALUES (3, 'd', 'F')
INSERT INTO @.Actual VALUES (5, 'd', 'F')
INSERT INTO @.Actual VALUES (5, 'e', 'F')
INSERT INTO @.Actual VALUES (6, 'f', 'F')
INSERT INTO @.Actual VALUES (7, 'g', 'F')|||Never mind. I think I have a solution. Thanks for your time Pat.sql
Monday, March 19, 2012
help with a query
this query don't work
use Common
go
declare @.DateTable Varchar(8)
declare @.TableName Varchar (255)
declare @.Currency Varchar (3)
select substring (TABLE_NAME,1,8) as date FROM information_schema.tables where TABLE_NAME not like 'IIM%' and TABLE_NAME not like 'sys%'
select substring (TABLE_NAME,9,11) as Currency FROM information_schema.tables where TABLE_NAME not like 'IIM%' and TABLE_NAME not like 'sys%'
set @.DateTable = date
set @.Currency = Currency
SELECT @.TableName = TABLE_NAME
FROM information_schema.tables
where TABLE_NAME not like 'IIM%' and TABLE_NAME not like 'sys%'
INSERT INTO [Common].[dbo].[IIM_RM_EXP_EUR_TEMP]
([Sedol]
,[Date]
,[Currency]
,[Name]
,[Candidate]
,[Benchmark]
,[Min]
,[Max]
,[Initial]
,[Alpha]
,[Specific]
,[Total]
,[Price]
,[Beta]
,[Buy.Cost]
,[Sell.Cost]
,[Factor.1]
,[Factor.2]
,[Factor.3]
,[Factor.4]
,[Factor.5]
,[Factor.6]
,[Factor.7]
,[Factor.8]
,[Factor.9]
,[Factor.10]
,[Factor.11]
,[Factor.12]
,[Factor.13]
,[Factor.14]
,[Factor.15]
,[Factor.16]
,[Factor.17]
,[Factor.18]
,[Factor.19]
,[Factor.20]
,[Factor.21]
,[Factor.22]
,[Factor.23]
,[Factor.24]
,[Style.1]
,[Style.2]
,[Style.3]
,[Style.4]
,[Style.5]
,[Country.1]
,[Country.2]
,[Country.3]
,[Country.4]
,[Country.5]
,[Country.6]
,[Country.7]
,[Country.8]
,[Sector.1]
,[Sector.2]
,[Sector.3]
,[Sector.4]
,[Sector.5]
,[Sector.6]
,[Sector.7]
,[Sector.8]
,[Sector.9]
,[Sector.10]
,[Sector.11]
,[Sector.12]
,[Sector.13]
,[Sector.14]
,[Sector.15]
,[Sector.16]
,[Sector.17]
,[Sector.18]
,[Group.1]
,[Group.2]
,[Group.3]
,[Group.4]
,[Group.5]
,[Group.6]
,[Group.7]
,[Group.8]
,[Group.9]
,[Group.10]
)
SELECT [ID]
,'@.DateTable'
,'@.Currency'
,[Name]
,[Candidate]
,[Benchmark]
,cast ([Min] as real)
,cast ([Max] as real)
,cast ([Initial] as real)
,cast ([Alpha] as real)
,cast ([Specific]as real)
,cast ([Total] as real )
,cast ([Price] as real)
,cast([Beta]as real)
,cast([Buy#Cost]as int)
,cast([Sell#Cost]as int)
,cast([Factor#1]as real)
,cast([Factor#2]as real)
,cast([Factor#3]as real)
,cast([Factor#4]as real)
,cast([Factor#5]as real)
,cast([Factor#6]as real)
,cast([Factor#7]as real)
,cast([Factor#8]as real)
,cast([Factor#9]as real)
,cast([Factor#10]as real)
,cast([Factor#11]as real)
,cast([Factor#12]as real)
,cast([Factor#13]as real)
,cast([Factor#14]as real)
,cast([Factor#15]as real)
,cast([Factor#16]as real)
,cast([Factor#17]as real)
,cast([Factor#18]as real)
,cast([Factor#19]as real)
,cast([Factor#20]as real)
,cast([Factor#21]as real)
,cast([Factor#22]as real)
,cast([Factor#23]as real)
,cast([Factor#24]as real)
,cast([Style#1]as Char)
,cast([Style#2]as Char)
,cast([Style#3]as Char)
,cast([Style#4]as Char)
,cast([Style#5]as Char)
,cast([Country#1]as Char)
,cast([Country#2]as Char)
,cast([Country#3]as Char)
,cast([Country#4]as Char)
,cast([Country#5]as Char)
,cast([Country#6]as Char)
,cast([Country#7]as Char)
,cast([Country#8]as Char)
,cast([Sector#1]as Char)
,cast([Sector#2]as Char)
,cast([Sector#3]as Char)
,cast([Sector#4]as Char)
,cast([Sector#5]as Char)
,cast([Sector#6]as Char)
,cast([Sector#7]as Char)
,cast([Sector#8]as Char)
,cast([Sector#9]as Char)
,cast([Sector#10]as Char)
,cast([Sector#11]as Char)
,cast([Sector#12]as Char)
,cast([Sector#13]as Char)
,cast([Sector#14]as Char)
,cast([Sector#15]as Char)
,cast([Sector#16]as Char)
,cast([Sector#17]as Char)
,cast([Sector#18]as Char)
,cast([Group#1]as Char)
,cast([Group#2]as Char)
,cast([Group#3]as Char)
,cast([Group#4]as Char)
,cast([Group#5]as Char)
,cast([Group#6]as Char)
,cast([Group#7]as Char)
,cast([Group#8]as Char)
,cast([Group#9]as Char)
,cast([Group#10]as Char)
FROM [Common].[dbo].[@.TableName]
You can't do:
FROM [Common].[dbo].[@.TableName]
In order to do this, you'll need to dynamically create the insert statement and use EXEC
eg
Code Snippet
DECLARE @.TableName VARCHAR(100)
SET @.TableName = 'sys.objects'
EXEC ('SELECT * FROM ' + @.TableName)
Help with a query
Monday, March 12, 2012
Help with "Error converting data type varchar to float"
I am getting this error. Any one there to guide meYou have come to the right place. We are all mind readers here. We scan your brains alpha waves and decode it into the source code you are looking at that generated this error.|||Unfortunately, I am not receiving any signal from my scan. *shrug* I am also fighting off a cold though, so it could be a blockage on my side.
My best guess given the information you have provided so far is that you are attempting in your code to convert a varchar-format variable or constant containing a date into a float datatype.
This is a no-no in most technical (and social, for that matter) circles.|||Actually u should first tell that where this problem is coming in ur source code or database script|||I am getting this error. Any one there to guide meI knew a girl like that once...
On a more serious note, can you give us something more to work with to help you solve your problem? Please post the SQL code that you were running when you got this error. Look here (http://www.dbforums.com/showthread.php?t=1196943) for more detailed help.
-PatP
Friday, March 9, 2012
Help variable in SP
Dear All
CREATE PROCEDURE test AS
declare @.tableName varchar(100)
set @.tableName='ABCD'
INSERT INTO @.tableName
(A, B, C, E, F,G,H)
SELECT
A, B, C, D,
COUNT(*) AS G,
CONVERT(varchar(10), RecDate, 121), Left(TransID, 2) AS J
FROM
dbo.EFG
GROUP BY
ORDER BY
XXXX
( error INSERT INTO @.tableName, Do not find @.tableName, must be declare.)
help thanks
William
It appears that you first create @.TableName as a scalar variable, and then you attempt to insert into it as though it were a table variable.
If that properly reflects your intentions, I suggest that you first declare @.TableName as a table variable, with the columns properly defined -then your insert should work.
|||You are trying to insert the values on the table which is given on the runtime. Typically it is a dynamic insert query.
Use the following query..
Code Snippet
CREATE PROCEDURE test AS
Declare @.tableName varchar(100)
Set @.tableName='ABCD'
Exec ('INSERT INTO ' + @.tableName + '(A, B, C, E, F,G,H)
SELECT
A, B, C, D,
COUNT(*) AS G,
CONVERT(varchar(10), RecDate, 121), Left(TransID, 2) AS J
FROM
dbo.EFG
GROUP BY XXXX
ORDER BY XXXX');
|||How to do?|||Thanks all|||
CREATE PROCEDURE test AS
declare @.tableName varchar(100)
set @.tableName='ABCD'
INSERT INTO @.tableName
(A, B, C, E, F,G,H)
SELECT
A, B, C, D,
COUNT(*) AS G,
CONVERT(varchar(10), RecDate, 121), Left(TransID, 2) AS J
FROM
dbo.EFG
GROUP BY
ORDER BY
XXXX
NOTE: You MUST supply the correct datatypes below. This is a suggested format to DECLARE a table variable and then populate that table variable.
Code Snippet
CREATE PROCEDURE dbo.MyTestProcedure
AS
BEGIN
DECLARE @.MyTable table
( ColA datatype,
ColB datatype,
ColC datatype,
ColD datatype,
ColE datatype,
ColF datatype,
ColG datatype
)
INSERT INTO @.MyTable
SELECT Col1,
Col2,
Col3,
Col4,
COUNT(*),
CONVERT(varchar(10), RecDate, 121),
Left(TransID, 2)
FROM dbo.EFG
GROUP BY
ORDER BY
SELECT *
FROM @.MyTable
END
Sunday, February 19, 2012
Help Reqd Urgently (SQL Query)
Table Name: ChemoAdmin
Fields:
Field Name: Field Type: Typical Value:
patientID (Varchar 10) XYZABC001
stationDate (DateTime) 09/17/2004
drugName (Varchar 25) Drug 1
dose (Numeric) 5
doseUnit (Varchar 5) mg
I require the following output using one query:--
DATE 09/17/2004 09/21/2004
Drug 1 5 mg Nil
Drug 2 2 mg 4 mg
Drug 3 Nil 1 mg
Pls help.You mean you'd like a specify a daterange and have it shown above the other results returned by the same select-statement (seperated by an empty line)?
Is there any reason why you need this in a single sql-statement?|||It is better if this can be done using one select statement. Because, I would like to create a view that would give the output as shown.|||I don't see a way of doing that in a view. You might want to create a stored procedure instead that produces both the daterange as well as the select output. However, I feel that your aim is off.|||this requires a full outer join
however, i personally never write a full outer join, particularly when there is a join condition on only one of the tables, as in this case
i always write a full outer join as a left outer join unioned with a right outer join where there's no matching row (and then i always flip the right outer join over into a left)
select t1.drugName
, t1.dose
, t1.doseUnit
, t2.dose
, t2.doseUnit
from ChemoAdmin as t1
left outer
join ChemoAdmin as t2
on t1.drugName
= t2.drugName
and t2.stationDate = '2004-09-21'
where t1.stationDate = '2004-09-17'
union all
select t1.drugName
, t1.dose
, t1.doseUnit
, t2.dose
, t2.doseUnit
from ChemoAdmin as t2
left outer
join ChemoAdmin as t1
on t2.drugName
= t1.drugName
and t1.stationDate = '2004-09-17'
where t2.stationDate = '2004-09-21'
and t1.drugName is null|||this requires a full outer join
however, i personally never write a full outer join, particularly when there is a join condition on only one of the tables, as in this caseOk, that just begs the question: Why do you avoid FULL OUTER JOIN when it does exactly what is needed? While I use FULL and CROSS joins rather sparingly, when they do exactly what I want I'll cheerfully use the little beggars.
-PatP|||because not every database supports FULL OUTER (yes, i know that microsoft sql server does, but it's easier remembering the workaround than trying to remember which database supports it)
but more importantly, in this instance the join condition include conditions on only one table or the other
i'm not certain that this will produce the same results:select t1.drugName
, t1.dose
, t1.doseUnit
, t2.dose
, t2.doseUnit
from ChemoAdmin as t1
full outer
join ChemoAdmin as t2
on t1.drugName
= t2.drugName
and t1.stationDate = '2004-09-17'
and t2.stationDate = '2004-09-21'
feel like testing it for us? :)|||Because your code tests both tables, it effectively reduces the join to a conventional INNER join. Any result set rows that "miss" (either right or left) will fail due to the comparison with NULL. The only difference between the two (FULL versus unions of left and right) would be if you used UNION instead of UNION ALL.
-PatP|||so you're saying that the FULL OUTER example that i posted will not work?
so what would you do to make it work in this particular example?
don't forget, you pooh-poohed my original solution and suggested i should've used a FULL OUTER, and i'd like to see it|||Can any drug in your list have more than 2 dosages ? if so joining the table just twice wont work. Use the following query to find the maximum number of doses for any drug in that table.
select max(counter) max_number from
(select drugName, count(*) counter from ChemoAdmin
group by ChemoAdmin) derived
if the max_number is very high and likely to be a variable then the best way is to use a stored procedure.
if it is just 2 or 3 then, the you can use the self left outer joins not a full outer join
for instance if the max_number is 2 then
select t1.drugName
, t1.dose
, t1.doseUnit
, t2.dose
, t2.doseUnit
from ChemoAdmin as t1
left outer
join ChemoAdmin as t2
on t1.drugName
= t2.drugName
and t1.stationDate >= '2004-09-17'
and t1.stationDate < '2004-09-21'
and t2.stationDate >= '2004-09-17'
and t2.stationDate < '2004-09-21'
and t1.dose <> t2.dose
and t1.doseUnit <> t2.doseUnit
if the max_number is 3 then join the result again with the table and so on, but do not join too many times though because it would cause performance problems.|||so you're saying that the FULL OUTER example that i posted will not work?
so what would you do to make it work in this particular example?
don't forget, you pooh-poohed my original solution and suggested i should've used a FULL OUTER, and i'd like to see itI didn't pooh on anything. In my first post I just asked why you avoided a FULL join when I use them occaisionally.
The point that I raised in my second post is that if you look at things from the set based perspective, if either set it empty (returning NULL in SQL) then the WHERE clause comparison has to fail, reducing the result set to the intersection (an INNER join in SQL) or less.
Sorry if you got the impression that I was denigrating your work around for a full join. I didn't mean to do that at all.
I'm still not at all convinced that we understand what the original poster wanted. They showed us a third of the equation (the results they want), without giving us either the input data or the rules they used to determine the output. Before we debate the relative merits of solutions, we need to understand what the rules are!
-PatP|||I'm still not at all convinced that we understand what the original poster wanted. so true
but then, the most interesting threads are where the original poster asks something innocuous (to them) and we just run with it in all sorts of directions
:rolleyes:
Help Reqd Urgently (SQL Query)
Table Name: ChemoAdmin
Fields:
Field Name: Field Type: Typical Value:
patientID (Varchar 10) XYZABC001
stationDate (DateTime) 09/17/2004
drugName (Varchar 25) Drug 1
dose (Numeric) 5
doseUnit (Varchar 5) mg
I require the following output using one query:--
DATE 09/17/2004 09/21/2004
Drug 1 5 mg Nil
Drug 2 2 mg 4 mg
Drug 3 Nil 1 mg
Pls help.Sorry, but I'm confused. What is your question?
-PatP
help regarding this search
//and i m getting this error
Syntax error converting the varchar value 'NPO04/136 ' to a column of data type int.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'NPO04/136 ' to a column of data type int.
====================================
can anyone help me in this i m doing a search in a form ( for ex. u search for clientID n it'll come up in search result n once u select that it'll fill in the form) if anyone knw how to do this plz help me. thank u
Protected
Sub cmdSelect2_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles cmdSelect2.ClickDim sIDAsStringsID = lstResults.SelectedValue
Dim iIDAsInteger' iID = Int32.Parse(sID)'' If iID > 0 ThenDim selectSQLAsStringselectSQL =
"SELECT * FROM contactinfo "selectSQL &=
"WHERE ClientID=@.ClientID"Dim cmdAsNew SqlCommand(selectSQL, conSR)cmd.Parameters.AddWithValue(
"@.ClientID", iID)Dim readerAs SqlDataReaderTry
conSR.Open()
reader = cmd.ExecuteReader()
reader.Read()
' Fill the controls.'txtCaseid.Text = reader("Caseid").ToString()
txtClientID.Text = reader(
"ClientID").ToString()txtFirstname.Text = reader(
"Client_Fname").ToString()txtLastname.Text = reader(
"Client_Lname").ToString()txtRace.Text = reader(
"Race").ToString()txtCounty.Text = reader(
"County_of_origin").ToString()txtGender.Text = reader(
"Gender").ToString()txtState.Text = reader(
"State").ToString()txtReligion.Text = reader(
"Religion").ToString()txtContactID.Text = reader(
"ContactID").ToString()'reader.Close()'' enable_fields()lblResults.Text =
""Catch exAs Exception'lblResults.Text = "Error inserting record"lblResults.Text =
"Error inserting record"lblResults.Text = ex.Message
FinallyconSR.Close()
EndTrylblID.Text = sID
phID.Visible =
TruetxtID.Text = sID
txtAct.Text =
"edit"cmdSubmit.Text =
"Update"lblCurrentAct.Text =
"Update Existing Record"'Else'If iID = 0 Then' lblResults.Text = "Client not found in Contact Information."'Else' lblResults.Text = "Please select a contact from the list."''' End IfEndSubHello my friend,
The field you wish to search by has non-numeric data in it so use a string to pass as the parameter instead of an int. You pass in iID so it crashes. Use a string variable instead and you should be fine.
Kind regards
Scotty