Showing posts with label single. Show all posts
Showing posts with label single. Show all posts

Friday, March 23, 2012

How to run multiple sql statements from a single file?

Hi,
I am wondering if anyone has any examples of how to run multiple sql statements from a file using .net? I want to automatically install any stored procedures or scripts from a single file on the server when my web application runs for the first time. Thanks for your help in advance!

You use SP_EXECUTESQL for that in SQL Server, it is a system stored procedure in the Master database. Try the link below for Microsoft article about SP_EXECUTESQL and run a search for same in the BOL(books online) for more info. Hope this helps.

http://support.microsoft.com/default.aspx?scid=kb;en-us;262499

Friday, March 9, 2012

How to return a row counter?

Is it possible to return a row counter in a single select statement?
For example, I want to return Col1 and Col2 in TableA, but I need a counter
to identify the returned row's positioning.
RowCount ColA ColB
1 A B
2 C D
3 E F
I'd like to do it in a single select statement. If I have to declare a
variable and do a while statement, I could do it but it would be very
process-intensive.
Thanks!> Is it possible to return a row counter in a single select statement?
Sort of. But you really, really, really should consider appending this at
the presentation layer, which has to loop through all rows anyway. Doing
this at the database level forces SQL Server to inspect the entire set for
every row, and this will definitely have high potential to cause you some
performance issues.
http://www.aspfaq.com/2427|||Thanks, Aaron. I'll look into those options.
Do you know if Microsoft is planning on implementing this logic as a
function in the future?
"Aaron Bertrand [SQL Server MVP]" wrote:

> Sort of. But you really, really, really should consider appending this at
> the presentation layer, which has to loop through all rows anyway. Doing
> this at the database level forces SQL Server to inspect the entire set for
> every row, and this will definitely have high potential to cause you some
> performance issues.
> http://www.aspfaq.com/2427
>
>|||> Do you know if Microsoft is planning on implementing this logic as a
> function in the future?
Yes, SQL Server added ROW_NUMBER() and other ranking functions in SQL Server
2005.
http://msdn2.microsoft.com/en-us/library/ms186734

How to Retrive single data from sqldatasource control

hi,

i need to code for retrieving single data from sqldatasource control. i need the full set of coding

connecting
retrieving data in text box
editing data to the table
updating data to the table
deleting data to the table

i want to fetch "single field data"

any one who know the code please post reply or send it to my mail senthilonline_foryou@.rediffmail.comI suggest that you use a stored procedure like this (assuming ID is an identity index column, with a data row NAME VARCHAR(50) in Table Fred)

CREATE PROCEDURE dbo.uspGetFred
(
@.ID INT,
@.NAME VARCHAR(50) OUTPUT
)
SET NOCOUNT ON
SELECT NAME FROM Fred WHERE ID = @.ID
GO

The VB code below retrieves NAME into aName fpor a given value of iID
CONST DBCONNECT As String = "Your Connect String"

Dim sName As String = ""
Dim xSqlConnection As SqlConnection = New SqlConnection(DBCONNECT )
Dim xSqlCommand As SqlCommand = New SqlCommand("uspGetFred", xSqlConnection)
Try
xSqlCommand.CommandType = CommandType.StoredProcedure
xSqlCommand.Parameters.Add("@.ID", SqlDbType.Int)
xSqlCommand.Parameters("@.ID").Value = CType(iId, Integer)
xSqlCommand.Parameters.Add("@.NAME", SqlDbType.VarChar, 50)
xSqlCommand.Parameters("@.NAME").Direction = ParameterDirection.Output
xSqlCommand.Connection.Open()
xSqlCommand.ExecuteNonQuery()
sName = xSqlCommand.Parameters("@.NAME").Value
Catch ex As Exception
' Handle your error here!
Finally
xSqlCommand.Connection.Close()
xSqlCommand.Dispose()
xSqlConnection.Dispose()
End Try

HTH!Idea

Wednesday, March 7, 2012

how to retrieve only the duplicates in a table

There is a table with a single column with 75 rows - 50 unique / 25
duplicates. How would pull back a list of the rows that have/are
duplicates?

This is a question that I got in an interview. I didn't get it,
obviously...

Thanks,

TimSELECT col1, col2, col3, ...
FROM Sometable
GROUP BY col1, col2, col3, ...
HAVING COUNT(*)>1

--
David Portas
----
Please reply only to the newsgroup
--

"TimG" <timgru@.hotmail.com> wrote in message
news:744d8a29.0311072031.75846c64@.posting.google.c om...
> There is a table with a single column with 75 rows - 50 unique / 25
> duplicates. How would pull back a list of the rows that have/are
> duplicates?
> This is a question that I got in an interview. I didn't get it,
> obviously...
> Thanks,
> Tim

Friday, February 24, 2012

how to retriece single record in database by using SqlDataSource??

Is me again,and now i facing problem to retrieve a single record from the database.

here is my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim user As String
user = TextBox1.Text
Dim varpassword
Dim mydata As SqlDataSource

mydata.SelectCommand = "Select * from tbluser where uLogin = '" & user & "'"
varpassword = mydata.SelectCommand.uPassword

End Sub
End Class

but i get the error : 'uPassword' is not a member of 'String'

i wan to retrieve the password of that user,can anyone help me?

thanksSmile

First create a select parameter "uPassword" of type "String".

|||

Girijesh:

First create a select parameter "uPassword" of type "String".

i not really understand about creating the select parameter.

can u write the line of code for me?thanksSmile

|||

Hi there,

Use this:

imports System.Data.Sql

Dim dt as new DataTable

Dim query As String = "Select * from tbluser where uLogin = '" & user & "'"

Dim conn as new SqlConnection(connection)

Dim adapter as new SqlDataAdapter

adapter.SelectCommand =new SqlCommand(query, conn);
adapter.Fill(dt);

// this DataTable only has one row, the one for this username

Dim password As String = dt.rows(0)("uPassword")

hope it helps you out,

gonzzas