|
How do you return the number of rows from the query? In other words if I have a variable intCount how do I set intCount to the "count" of the query?
Thanks for your reply. We've noticed a few security holes in our application in a few places and we are fixing those right now.
|
|
|
|
|
Dim cmd As SqlCommand
cmd = SqlCommand.New()
cmd.CommandText = "SELECT COUNT(*) FROM MyTable WHERE someColumn=@someValue"
cmd.Connection = myConnection
Dim numRows As Int
numRows = cmd.ExecuteScalar()
numRows will contain the number of rows that match the given filter (i.e. what is filtered in the WHERE clause). COUNT() is an aggregate function that returns a count, when COUNT(*) is used it returns the number of rows. If you use COUNT(columnName) then it will count the number of rows where the column value is not null.
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
This is the correct way. ExecuteNonQuery should be used for Insert/Update/Delete statements. If the CommandText is "SELECT" statment, then it will always return -1. When it is DML statement, then it will return the number of rows affected by that DML statement.
|
|
|
|
|
I have a program that converts excel to mssql. Does anyone know how to properly use it step-by-step?
|
|
|
|
|
vandread1 wrote: I have a program that converts excel to mssql. Does anyone know how to properly use it step-by-step?
I think you win the prize for the most vague question of the day.
vandread1 wrote: a program
"A program"? The indefinite article? Could you tell us to which program you are referring?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
vandread1 wrote: I have a program that converts excel to mssql. Does anyone know how to properly use it step-by-step?
Peers over your screen looks, I don’t see any program running that converts an Excel file to SQL server.
Is that you need to create a program that inserts data into a SQL table? What language are you planning on using? Which data connectivity model do you need to use?
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
Please im working on smart devices application on C# and i want to know how i can connect a database with it as the windows application.
im trying to use Using System.data.oledb
or Using System.data.sql
But no response.
so please please help me.
thanx and wish u solve me this problem
tedy
|
|
|
|
|
Follow this
http://www.csharphelp.com/archives3/archive586.html
Hope this helps
|
|
|
|
|
Hi all,
i am developing the website in ASP.NET using MS Access database, in this project client require ,at the end of every day the database should send a report via email of the upated record , means new user, new transaction etc to client automatically....
so any idea for this...
thanx
|
|
|
|
|
You can write a script (Javascript or vbscript) that sends the mail, and then schedule that script to run every day.
Wout Louwers
|
|
|
|
|
thanx for reply,
but how i can schedule that script to run every day in asp.net, its a main problem......
|
|
|
|
|
How can I return a set of records that are the result of different row operations
I have a table:
Mileage
(totalMiles id ...)
How can I get a result set of:
Row diff
1 (row1-row2)
2 (row2-row3)
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
Assuming your ID represents sequential order, you can use correlated sub queries to solve the problem. Something like this may work for you:
SELECT
id,
ISNULL(
totalMiles - (SELECT totalMiles
FROM Mileage
WHERE id= (SELECT MIN(id)
FROM Mileage
WHERE id > BaseMiles.id)),0) AS diff
FROM Mileage BaseMiles
ORDER BY id ASC
|
|
|
|
|
Hello Dears
>>>insert into tablename select * from DBName..TABLENAMEby using this Query i can insert datas from another database in the same machine. But when i am connect to remote machine using the following Query
insert into LOCAL SYSTEM TABLENAME select * from REMOTE SYSTEM NAME.REMOTE SYSTEN DATABASE..REMOTE SYSTEM TABLE NAME
i am getting error
"Server: Msg 7314, Level 16, State 1, Line 1
OLE DB provider 'SQLOLEDB' does not contain table '"DBNAME"."TABLE NAME"'"Please any one give me idea....
N.Rajakumar B.E.,
Application Developer,
|
|
|
|
|
When you are using a remote connection you have to specify the table-owner. Default this is dbo
So, what you can try is:
<br />
insert into tablename select * from [Remote System Name].[Remote Database].dbo.[TableName]<br />
Wout Louwers
|
|
|
|
|
Hi
I have a table which contains member_id as string field. In this field the values will be like
1.1.2
1.1.2
1.1.2.1
1.1.2.2.1
1.1.2.2.2 etc....
When i want to insert a new member i want to isert existig member's id + 1 .
Eg: if i select 1.1.2 as my manager my id should 1.1.2.3. Do you have any idea about this. Expectng your earliest reply
UK_Nair
|
|
|
|
|
You can do this in an preatty way :
In the server side of your application set the ID manually like this :
1) querry the database to return a single ID (TOP 1 if I remeber right) and sort the return descending.
Select member_id Top 1 From myTable Order By memberId DESC
2) do your stuff with the old ID an et the new intém's ID
3) add your new item
I hope you understand...because is a rough world out there...
|
|
|
|
|
This is probably a very simple problem but it's kicking my ass so I'll get right to it
I have a database table running of ms sql server 2000 which contains amoung other things three columns:
a DateTime which should hold only the date
a DateTime which should only hold a time
a DateTime which should also only hold a time
I need the three seperate DateTimes since the first is used in a storedprocedure to extract records based on the current day
the other two to be displayed in a datagrid as a start and stop time for an event or appointment.
now i can open enterprise manager and open the table directly and the start and stop datetime columns show the time just as i imputed it.
however as soon as my data adapter fills the dataset the datagrid displays an arbitray date (30/12/1899) but does not display the times.
is this something i have to fix on the database side with some input formating or can i control how a datagrid displays dates and times
any help would be seriously appreciated
Ryan
"It's nice to know if I ever need attention all I have to do is die."
|
|
|
|
|
Your problem may be because your faulty way of inserting data into the data base.
Perhaps some code example on how you insert and querry the data base wold help.
I hope you understand...because is a rough world out there...
|
|
|
|
|
The data is already in the db i've tried entering the fields that require just the time and not the date with:
1. only the time
2. the same date as the date only field + the time
the data all looks fine in the database itself
the problem is when the dataadapter fills my dataset (which is a auto generated typed dataset) the fields for the time only items still only show the date regardless if i entered it as 1 or 2 above
here's my stored procedure to look at too if that helps
ALTER PROCEDURE dbo.GetJobs
/*
(
@parameter1 datatype = default value,
@parameter2 datatype OUTPUT
)
*/
AS SELECT Job.JobID, Job.JobTitle, Job.JobTimeStart, Job.JobTimeStop
From Job
/* SET NOCOUNT ON */
RETURN
now running this stored procedure in vs returns only the time as they were entered into the db
now if i use the preview data option in vs for the data adapter suddenly that arbitrary date shows up but the time is gone.
also when i bind it to a datagrid control the same happens
when i tried binding one of the members that should return a time to a listbox it shows the same arbitray date plus the correct time.
so that tells me my stored procedure is working and even though it isn't showing everything the dataadapter is filling the dataset with the date and time for the db members correctly
so how do i change how the datagrid displays dates and times is it something i have to do at run time and if so what
Ryan
"Smile often!.... it distracts people while you load the gun."
|
|
|
|
|
Im not sure how much this would help, but have you tried the Format command when extracting the data?
Format(date, "hh:mm") as newdate {this is off the top of my head so its probally wrong, but should get you close}
Also does this help at all?
How to Set the Day/Month/Year Date Format in SQL Server[^]
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
Hey all,
I have DataRelation object between 2 tables & 2 DataGrids.
for some reasons, I delete the relation, activate an operation on the tables & then create the relation back. here is some code:
//before the operation starts:
Ds.Relations.Clear();
Ds.Tables["Cust2"].Constraints.Clear();
//after the operation
DataColumn dc1 = Ds.Tables["Cust1"].Columns["Id"];
DataColumn dc2 = Ds.Tables["Cust2"].Columns["Id"];
DataRelation Dr = New DataRelation("cust1to2", dc1, dc2);
Ds.Relations.Add(Dr);
everything is ok until now.
but when I tried to connect the tables to the datagrids:
DtGrd1.SetDataBinding(Ds, "Cust1");
DtGrd2.SetDataBinding(Ds, "Cust1.cust1to2");
I get the exception:
"Cannot have a relationship between tables in different DataSets"
does anyone know what is going on??
thanks,
RoyRose
|
|
|
|
|
HI:everyone
like this
declare @myid smallint
select @myid = 55
kill @myid -- it general some errors
How can i do it ?
POWER
|
|
|
|
|
Try:
declare @myid smallint <br />
select @myid = 53 <br />
<br />
declare @sql varchar(30)<br />
<br />
set @sql = 'kill ' + cast(@myid as varchar(20))<br />
<br />
exec (@sql)
Wout Louwers
|
|
|
|
|
Hi Guys..
I want to ask if there is a way to use *.sql files generated by MsSql Server (or written by someone )in the C#.
For e.g. i have a *.sql file and i want to create tables in my program using this script..
Is there any class in C# or u guys can give me a link ?
thx a lot..
good coding..!
|
|
|
|