Showing posts with label retrieving. Show all posts
Showing posts with label retrieving. Show all posts

Friday, March 9, 2012

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 the text of UDF in SQL Server 2005

In the previous versions of SQL Server, retrieving the text of User
Defined Functions was easy:
SELECT text FROM syscomments sc INNER JOIN sysobjects so ON sc.id =
so.id WHERE so.name = 'fn_dblog' ORDER BY sc.colid
For some reason the above statement doesn't work in SQL Server 2005 (it
works for procedures and for views, but not for functions).
How can I retrieve the text of User Defined Functions in SQL Server
2005?
TIA
Dariusz DziewialtowskiHi
No, it works very well for user's UDF as well. This udf is not created by
an user ,moreover if i'm mo mistaken it isnt supported by MS
However you can achive it by issuing
sp_helptext 'fn_dblog'
<dariusz.dziewialtowski@.gmail.com> wrote in message
news:1144554215.276141.57970@.u72g2000cwu.googlegroups.com...
> In the previous versions of SQL Server, retrieving the text of User
> Defined Functions was easy:
> SELECT text FROM syscomments sc INNER JOIN sysobjects so ON sc.id =
> so.id WHERE so.name = 'fn_dblog' ORDER BY sc.colid
> For some reason the above statement doesn't work in SQL Server 2005 (it
> works for procedures and for views, but not for functions).
> How can I retrieve the text of User Defined Functions in SQL Server
> 2005?
> TIA
> Dariusz Dziewialtowski
>|||Hi Uri,
Thank you for your help.

>This udf is not created by an user
Yes, I gave it only as an example.

>However you can achive it by issuing sp_helptext 'fn_dblog'
I didn't think of that - I have to retrieve the text programmatically,
from VB6 code, but if I cannot make the old method work - "SELECT text
FROM syscomments" - than I'll try to execute sp_helptext
programmatically.
Still it puzzles me why "SELECT text FROM syscomments" is failing for
User Defined Functions in SQL Server 2005.
Thanks again for your help.
Dariusz Dziewialtowski.|||(dariusz.dziewialtowski@.gmail.com) writes:
> Still it puzzles me why "SELECT text FROM syscomments" is failing for
> User Defined Functions in SQL Server 2005.
In general it isn't:
CREATE FUNCTION myudf() RETURNS int AS
BEGIN
RETURN (99)
END
go
SELECT text FROM syscomments WHERE id = object_id('myudf')
go
DROP FUNCTION myudf
works for me.
However, in your original post you had fn_dblog, and that function
has moved and no longer lives in master, as have all other system
procedures and system UDFs. They now live in the hidden resource
database.
Also beware that SQL 2005 completely changes how metadata is stored.
The system tables from SQL 2000 are now merely compatibility views
on top of the new catalog views. The catalog views in their turn
refers to the new system tables that are accessible outside system code.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Hello Erland,
Thank you for your help - I was not aware about the changes in metadata
in SQL Server 2005. Thanks a lot for explaining them to me.
Dariusz Dziewialtowski.

How to retrieve Member Properties in vb.net 2003 from MS AS 2000

Hi All,

We are facing one problem while retrieving member properties from MSAS 2000 using MDX query in VB.Net. we are able to retrieve the member properties like [Account].[All Account].[Net Income].[Total Expense] but i need the value should come like in this format [Account].[All Account].&[5000].&[5100] which is the member key value.

We are using ADOMD to connect MSOLAP and passing MDX query to retrieve the member properties. The below code which i used to retrieve in VB.Net.

Current Environment is VB.Net 2003 Framework, ADOMD and ADODB.

For intDimCount = 0 To cst.Axes(0).DimensionCount - 1

For intMem = 0 To cst.Axes(0).Positions.Count - 1

arrMem.Add(cst.Axes(0).Positions(intMem).Members(intDimCount).Caption)

arrMem.Add(cst.Axes(0).Positions(intMem).Members(intDimCount).UniqueName)

arrMem.Add(cst.Axes(0).Positions(intMem).Members(intDimCount).Name)

Next

Next

Could you please anyone to advise the same to retrieve member poperties( Name & Unique Name) like this [Account].[All Account].&[5000].&[5100].

Thanks,

Vishwesh

You can control the way the unique name is returned by adding a parameter to the connection string. This KB article explains the details http://support.microsoft.com/default.aspx/kb/304337

In AS2000 I think there was also a registry key setting, but the connection string option is probably better as then your application will be in control of how the unique names are formatted.

|||

Hi Darren,

I am Very thakful to u r reply.It is really helped to solve our Problem.

How to retrieve last inserted ID(Auto-Number) then perform another Insert Statement?

Hi All,

I hope you could help me in retrieving the last inserted ID(Auto-Number) then perform another Insert Statement?

I would really much appreciate it. I am coding in VB and am uisng

Visual Web Developer 2005 Express Edition and Microsoft SQL Sever

Management Studio Express.

Thanks alot.

-- Sam

My Codes:

Dim SQLStr5 As String = "INSERT INTO

NotesDetails(Notes_Level,Notes_Subject,Notes_Type,Notes_Year,Notes_Desc)

VALUES ('" & ddl_level.SelectedValue & "','" &

ddl_sub.SelectedValue & "','" & rbl_type.SelectedValue &

"','" & ddl_year.SelectedValue & "','" & tb_desc.Text &

"')"

Dim con5 As New SqlConnection(connstring)

con5.Open()

Dim cmd5 As New SqlCommand(SQLStr5, con5)

cmd5.ExecuteNonQuery()

con5.Close()

'' Need to get last inserted ID to Insert into the next Statement. (Notes_ID)

Dim SQLStr5a As String = "INSERT INTO

NotesComments(Notes_ID,Notes_Comments) VALUES ('" &

ddl_level.SelectedValue & "','" & tb_comments.Text & "')"

Dim con5a As New SqlConnection(connstring)

con5a.Open()

Dim cmd5a As New SqlCommand(SQLStr5a, con5a)

cmd5a.ExecuteNonQuery()

con5a.Close()

The last identity can be fetched using the SCOPE_IDENTITY() function, be aware that you have to do that within the same scope. As an additional new feature of SQL Server 2005 you could use the OUTPUT clause which give you the availbility to return values within the same DML statement. See more informations and samples in the BOL.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de