Wednesday, March 21, 2012
parse data
at will take each paramter and put it in a seperate field?
Go to Start --> Programs --> Microsoft SQL Server --> Server Network Utility. It should list the SQL Instances that you have installed on your computer. Hope this helps.
Tea C.
"sony5689" wrote:
> I am trying to parse some logs that I have already in a table and display them in another table or even on a web page (asp). The seperator is a & and a letter (ie &U=) that corrisponds to certain parameter. Does anyone have a script or stored procedure
that will take each paramter and put it in a seperate field?
Tuesday, March 20, 2012
Parent - Child
I have a recordset that I filter out, it has an ID, this table is called
'persons'
Then I have another table called 'children', this table has its own id's but
it also has the ID from 'persons'
So that one record from 'persons' could have one, none or multiple records
from 'children' which are linked by the ID of the person.
This is table persons:
ID - Autonumber
Name - nvarchar (Here goes the name of the person)
This is the children table:
ChildId - Autonumber
PersonId - ID from the persons table
Name - Name of the child
How can I return a query that will display one row ONLY for the 'person' and
then all the rows for the child that are linked to the 'person', could be
none or multiple rows.
I could not do this with a left join because if I did it would display the
name of the person several times.
I hope I explained myself.
A tutorial would be great.
Thanks,
AleksBetter to do this in your client app / reporting tool / programming language
.
AMB
"Aleks" wrote:
> I am using ASP/VB and MS SQL 2000
> I have a recordset that I filter out, it has an ID, this table is called
> 'persons'
> Then I have another table called 'children', this table has its own id's b
ut
> it also has the ID from 'persons'
> So that one record from 'persons' could have one, none or multiple records
> from 'children' which are linked by the ID of the person.
> This is table persons:
> ID - Autonumber
> Name - nvarchar (Here goes the name of the person)
> This is the children table:
> ChildId - Autonumber
> PersonId - ID from the persons table
> Name - Name of the child
> How can I return a query that will display one row ONLY for the 'person' a
nd
> then all the rows for the child that are linked to the 'person', could be
> none or multiple rows.
> I could not do this with a left join because if I did it would display the
> name of the person several times.
> I hope I explained myself.
> A tutorial would be great.
> Thanks,
> Aleks
>
>|||Try this:
select 'Person' as Source
, Person.Id as PersonId
, NULL as ChildId
, Person.Name
from Person
UNION ALL
select 'Child' as Source
, Child.PersonId as PersonId
, ChildId as ChildId
, Child.Name
from Child
Carl Federl
Please post DDL (create table) with datatypes, primary and foreign keys.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Paramter Passing
a url using ASP, as this will compromise our security ?
Thanks in advanceTwo options. 1. Use web services. 2. Pull the sensitive parameters by using
the global user!userid. This value tells you who is running the report and
you can then use that to query the database to find out the sensitive
parameters. You might need to do something like having a table with the
username, report and sensitive parameters that your write to before your
application calls the report. And, as I said, you can also use web services.
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Con" <conh@.melbournehosting.com> wrote in message
news:u8z7eiPvEHA.3276@.TK2MSFTNGP15.phx.gbl...
> Is it possible to pass variables/parameters to a report other thank
through
> a url using ASP, as this will compromise our security ?
> Thanks in advance
>
Monday, March 12, 2012
Parameters to insert data from form into SQL database
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0
That's what you inserted. :-)
Try:
cmdTest.Parameters("@.FirstN").Value = "John"
cmdTest.Parameters("@.LastN").Value = "Doe"
cmdTest.Parameters("@.Org").Value = "FLy by Night Airlines"
cmdTest.Parameters("@.Addr1").Value = "123 Main St"
cmdTest.Parameters("@.City").Value = "Anytown"
cmdTest.Parameters("@.Email").Value = nospam@.nospam.com
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
<hery@.infoventures.com> wrote in message
news:1141152263.896973.136620@.p10g2000cwp.googlegr oups.com...
Hi,
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0
|||Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0
|||I'd check the database directly with Query Analyzer (QA) if you're using SQL
2000 or SQL Server Management Studio (SSMS) if you're using SQL 2005. Also,
consider using SQL Profiler to see what is being sent to SQL Server. There
could be a problem in your VB .NET code somewhere.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
<hery@.infoventures.com> wrote in message
news:1141156805.957210.276400@.j33g2000cwa.googlegr oups.com...
Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0
Parameters to insert data from form into SQL database
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0That's what you inserted. :-)
Try:
cmdTest.Parameters("@.FirstN").Value = "John"
cmdTest.Parameters("@.LastN").Value = "Doe"
cmdTest.Parameters("@.Org").Value = "FLy by Night Airlines"
cmdTest.Parameters("@.Addr1").Value = "123 Main St"
cmdTest.Parameters("@.City").Value = "Anytown"
cmdTest.Parameters("@.Email").Value = nospam@.nospam.com
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
<hery@.infoventures.com> wrote in message
news:1141152263.896973.136620@.p10g2000cwp.googlegroups.com...
Hi,
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0|||Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0|||I'd check the database directly with Query Analyzer (QA) if you're using SQL
2000 or SQL Server Management Studio (SSMS) if you're using SQL 2005. Also,
consider using SQL Profiler to see what is being sent to SQL Server. There
could be a problem in your VB .NET code somewhere.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
<hery@.infoventures.com> wrote in message
news:1141156805.957210.276400@.j33g2000cwa.googlegroups.com...
Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0
Parameters to insert data from form into SQL database
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0That's what you inserted. :-)
Try:
cmdTest.Parameters("@.FirstN").Value = "John"
cmdTest.Parameters("@.LastN").Value = "Doe"
cmdTest.Parameters("@.Org").Value = "FLy by Night Airlines"
cmdTest.Parameters("@.Addr1").Value = "123 Main St"
cmdTest.Parameters("@.City").Value = "Anytown"
cmdTest.Parameters("@.Email").Value = nospam@.nospam.com
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
<hery@.infoventures.com> wrote in message
news:1141152263.896973.136620@.p10g2000cwp.googlegroups.com...
Hi,
I'm having problem inserting and storing data from asp.net web form to
SQL database. I use the following parameters for the SqlCommand object
to do the insert:
cmdTest.Parameters.Add(New SqlParameter("@.FirstN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.LastN",
SqlDbType.NVarChar, 25))
cmdTest.Parameters.Add(New SqlParameter("@.Org",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Addr1",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.City",
SqlDbType.NVarChar, 50))
cmdTest.Parameters.Add(New SqlParameter("@.Email",
SqlDbType.NVarChar, 50))
cmdTest.Parameters("@.FirstN").Value = "FirstN"
cmdTest.Parameters("@.LastN").Value = "LastN"
cmdTest.Parameters("@.Org").Value = "Org"
cmdTest.Parameters("@.Addr1").Value = "Addr1"
cmdTest.Parameters("@.City").Value = "City"
cmdTest.Parameters("@.Email").Value = "Email"
It seems like the value of the fields didn't get inserted when I submit
the page. All I'm getting is just the names of the fields (e.g. FirstN,
LastN), not the values themselves (e.g. John, Doe).
Can anyone help me?
Thanks,
hfk0|||Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0|||I'd check the database directly with Query Analyzer (QA) if you're using SQL
2000 or SQL Server Management Studio (SSMS) if you're using SQL 2005. Also,
consider using SQL Profiler to see what is being sent to SQL Server. There
could be a problem in your VB .NET code somewhere.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
<hery@.infoventures.com> wrote in message
news:1141156805.957210.276400@.j33g2000cwa.googlegroups.com...
Hi Tom,
Oh ok I get it now...I guess whatever I put within the "" is what is
inserted.
I'm also adding the following parameters:
cmdTest.Parameters.Add(New SqlParameter("@.State", SqlDbType.NChar, 2))
cmdTest.Parameters.Add(New SqlParameter("@.Phone", SqlDbType.NChar, 10))
cmdTest.Parameters("@.State").Value = State.SelectedItem.Value
cmdTest.Parameters("@.Phone").Value = Phone.Text
When viewing the page, somehow these two values didn't get inserted to
the database.
Did I use the wrong data type?
Thanks again,
hfk0
Parameters passed to Stored Procedure from ASP
For instance, a user selects 1,3,5 and 6. These would need to be passed to the sp and then:
...FROM [tablename]
WHERE (Number = @.param1) OR (Number = @.param2) OR (Number = @.param3) OR (Number = @.param4) etc...
This sp ties into a Crystal Report and in the above scenario, should return data for colums equal to 1 3 5 and 6. If only 1 and 6 had been selected on the ASP page, then only those two would be assigned a value in the sp.
Any suggestions?
Thanks in advance...
IIS 5.0, Win 2k, MSSQL 7.0Just create an ado connection/command objects and execute the stored procedure. What are the ranges for the parameters ?|||Looks like you want to say something like
WHERE col1 IN (@.param1, @.param2, @.param3, @.param4)
Or
WHERE col1 IN (@.param1, @.param2)
whatever the case may be...is that right?
Or are they diferent columns|||Well, if the ASP was passing three different parameters (Start Date, End Date, Details) they would be passed to the sp like(whereas the strStartDate, strEndDate and strDetails were assigned the Request.Form values):
Set ThisParam = StoredProcParamCollection.item(1)
ThisParam.SetCurrentValue cstr(strStartDate), 12
Set ThisParam = StoredProcParamCollection.item(2)
ThisParam.SetCurrentValue cstr(strEndDate), 12
Set ThisParam = StoredProcParamCollection.item(3)
ThisParam.SetCurrentValue cstr(strDetails), 12
However, in my scenario, I need to allow for multiple selections in one Request.Form("select") collection so to speak passed to the sp.
Does that make sense??
:-\|||What is the maximum number of selections in the select box - and will this keep growing ?|||The select box as 12 selections. The user can pick as few as one or as many as all. Basically, any combination. Say they pick 1 & 2. I need to pass those selections to the sp and use those parameters in the where
WHERE [columnname] = @.parameter1 or [columnname] = @.parameter2 or [columnname] = @.parameter3(parameter 3 remains default value since only 1 and two were passed in)
(The parameters are assign the passed values or remain default if no value passed)|||How come you don't ask for a variable result set from the SELECT..can't they pick their own fields too?
Don't want to use the D word....
Have you run a sql statement with all 13 parameters?
Can we see the sproc...
Is it like CREATE PROC mySproc @.Param1 = null, @.Param2 = null
Maybe you can pass all of them
and do WHERE Col1 = ISNULL(@.Param1,Col1) AND...|||You could set up one parameter and pass a delimited string containing all your selections.
You then split the string up and use the in statement to do your selection.
It's not pretty but it will work.
Let me know if you want details of how to do this.|||Brett & rokslide, thanks for the help. Basically, the options aren't added from a db connection into the asp page. So, hard coding the 12 values (which never change as they are campus locations) isn't a problem. So, the intent was to pass any combination of selected campuses, pass them to a sp and generate a report for the campuses selected.
...FROM [tablename]
WHERE (Number = @.param1) OR (Number = @.param2) OR (Number = @.param3) OR (Number = @.param4) etc...
Is basically what I need to do, but I like the delimited idea and splitting the string and doing the select through iteration.
Wednesday, March 7, 2012
parameters from asp.net
I am new to Reporting Services so I have a basic question. I would like to
start a report from an asp.net application, and I also want to send a
parameter to the report from the asp.net page. How do I do this. Is there a
nice example somehwere that I can look at.
Thanks
JuliaIf you don't mind using the querystring method it's pretty easy to pass in a
paramater.
http://msdn2.microsoft.com/en-us/library/aa256621(SQL.80).aspx
That should have everything you need.
From the URL Access Syntax:
http://server/virtualroot?[/pathinfo]&prefix:param=value[&prefix:param=value]...n]
Just drop the prefix: to pass it a report parameter.
"Julia" wrote:
> Hi
> I am new to Reporting Services so I have a basic question. I would like to
> start a report from an asp.net application, and I also want to send a
> parameter to the report from the asp.net page. How do I do this. Is there a
> nice example somehwere that I can look at.
> Thanks
> Julia
Monday, February 20, 2012
Parameterized query returns one row with null values.
I am hoping someone could help me understand why this is happening and perhaps a solution.
I am using ASP.NET 2.0 with a SQL 2005 database.
In code behind, I am performing a query using a parameter as below:
sql = "SELECT field_name FROM myTable WHERE (field_name = @.P1)"
objCommand.Parameters.Add(New SqlParameter("@.P1", TextBox1.Text))
The parameter is obtained from TextBox1 which has valid input. However, the value is not in the table. The query should not return ANY results. However, I am getting one single row back with null values for each field requested in the query.
The SQL user account for this query has select, insert, and update permissions on the table. The query is simple, no joins, and the table has no null values in any fields. If I perform the exact same query using an account with select only permission on the table, I get what I was expecting, no records. Then if I go back to the previous user account with more permissioins, and I change the query to pass the paramter this way:
sql =String.Format("SELECT field_name FROM myTable WHERE (field_name = {0})", TextBox1.Text)
I also get NO records retuned using the same criteria.
What is going on here? I would prefer to use the parameterized query method with the account having elevated permissions. Is there some command object setting that can prevent the null row from returning?
Thanks!
I am not sure but see if adding the datatype helps:
objCommand.Parameters.Add(New SqlParameter("@.P1", SqlDbType.Varchar,30)).value = TextBox1.Text|||Thanks for the suggestion. I tried adding the data type as you suggested. It did not change the results.
I have found that if I change to a data reader, the null value is not being returned. So, now it looks to be related to the ExecuteScalar method.
|||
I also just realized that it is not a null value being returned but instead an empty value, ie "".
I can get around this easily enough in multiple ways, I am just wanting to understand why this is happening.
So far I have this narrowed down to the following:
A parameterized query, with a user account having select, insert, update permission, and using the ExecuteScalar method. This combination returns a record with an empty result when the criteria is not found in the table instead of returning no records at all.
|||
Eh?
ExecuteScalar is used to return the first column of the first row of the query. If there is no rows, the value comes back as null.
I think perhaps you are misunderstanding what ExecuteScalar is supposed to do. It doesn't return records, or recordsets, it returns a singular scalar value (One column of one row - the first of each).
For further help, please post the whole code block in question. How you initialize your connection, command objects, how you are actually executing the query, where you are storing the result of the query (And how it is defined), and what you expected the result to be, and what you actually got.
If the results are varying depending on what user is executing the query, please make sure that either you explicitly define the schema you want to use, or that there doesn't exist multiple tables with the same name under different schemas (Refer to the table as dbo.Table not just Table).
|||Ok, my bad, stupid mistake(s) with both user permissions and also with the string.format method.
I at least have it consistenly returning the empty record.
One last question, why return null/empty instead of just nothing like a data reader?
Thank you very much for the response.
|||Hi,
ExecuteScalar is designed to return a single value from a database command and the proper representation of a single non-existant value is returning null. The ExecuteScalar is a non-void method and should return something!
Enjoy C#,
Mehrdad
|||Thank you to everyone for the help and clairification on ExecuteScalar.