Showing posts with label username. Show all posts
Showing posts with label username. Show all posts

Wednesday, March 21, 2012

DataRow syntax

command.CommandText = "SELECT UserName from Users WHERE UserID = " = userID

Executing this command returns one table with one column with one row. What is the syntax for getting that value into a variable? I can get the information into a dataSet but I can't get it out. Should I be using a dataSet for this operation?

The rest of the code so far:

SqlDataAdapter dataAdapter =newSqlDataAdapter();

dataAdapter.SelectCommand = command;

dataAdapter.TableMappings.Add("Table","Users");

dataSet =newDataSet();

dataAdapter.Fill(dataSet);

Using that code, your data would be in dataSet.tables[0].rows[0][0].

If that's always just returning one value, you might want to look into using ExecuteScalar instead of the adapter and dataset.

|||

You can just use executeScalar method of SQl command below is example from VB.Net help for scalar modified a little:

Public Function AddProductCategory( _ ByVal UserID As Integer, ByVal connString As String) As Integer Dim Username As string = "" Dim sql As String = "SELECT UserName from Users WHERE UserID = @.USERID" Using conn As New SqlConnection(connString) Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.Add("@.USERID", SqlDbType.Int) cmd.Parameters("@.USERID").Value = newName Try conn.Open() userName = Convert.ToInt32(cmd.ExecuteScalar()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using Return newProdIDEnd Function
Thanks
|||

Got it working ... thank you for your help!

Tuesday, February 14, 2012

database usage

I have an application which uses a special login credential (username and
password) to access several sql databases.
Its installed on several clients. what's the best possible way to determine
what all databases the application connected to, at the end of the day from
SQL Server Side. ?
thxskg,
You did not tell us which interface are you using to connect to sql server.
In case you are using ADO or ADO.NET, you can setup the property "Applicatio
n
Name" in the connection string. Then you will be able to use sp_who2 or
sysprocesses and look for that value.
AMB
"skg" wrote:

> I have an application which uses a special login credential (username and
> password) to access several sql databases.
> Its installed on several clients. what's the best possible way to determin
e
> what all databases the application connected to, at the end of the day fro
m
> SQL Server Side. ?
> thx
>
>|||Thanks!!. I am using ado.net. The clients can close the application at the
end of the day.
In that case i will not be able to find out, which database.
What iam looking for is whethere there is a record whether a user logged in
a particular database today?
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:ED55575B-B66A-489A-8B3B-B2770446B696@.microsoft.com...
> skg,
> You did not tell us which interface are you using to connect to sql
> server.
> In case you are using ADO or ADO.NET, you can setup the property
> "Application
> Name" in the connection string. Then you will be able to use sp_who2 or
> sysprocesses and look for that value.
>
> AMB
> "skg" wrote:
>