Showing posts with label app. Show all posts
Showing posts with label app. Show all posts

Friday, March 30, 2012

How to get todays date in format YY/MM/DD and to compare it to another date passed into th

I need to do the following and am hoping someone can help me out.

I have C#(asp.net app) that will call a stored procedure. The C# will pass in a date to the
stored procedure. The date is in the format YY/MM/DD. Once inside of the stored procedure, the date
passed into the stored proc needs to be compared to todays date. Todays date must be determined in
the SQL.

So basically here is my pseudo code for what I am trying to accomplish. Basically I just am after
the comparison of the two values:

If @.BeginDate < TodaysDate

The difficult part is how to obtain the value for "TodaysDate"

Taking into consideration that "TodaysDate" should probably be in the format of YY/MM/DD considering that is how the date it is to be compared with is being passed in.

Can someone please code this out for me in Microsoft SQL. I would be forever grateful.

I figured out what I needed to know, but will have further questions and will need help. Thanks to all.

Wednesday, March 28, 2012

how to get the results of sp_stored_procedures in C# app?

The result of sp_stored_procedures and many others is a result set, a table, but this procedure and others return only an integer. How do I get the result set in C# code? I need a general idea how it is done.

Thanks.

Are you looking for something like this:

using (SqlConnection cxn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Master;Integrated Security=True"))
{
cxn.Open();
SqlCommand cmd = new SqlCommand("sp_stored_procedures", cxn);
SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

while (rdr.Read())
{
for (int i = 0; i < rdr.FieldCount; i++)
{
Console.Write(rdrIdea.ToString() + "\t");
}
Console.WriteLine();
}

cmd.Dispose();
}

|||

If the procedure provides more than one resultsset, you will have to switch between the resultsets to retrieve the resultset you want to get. ( As a procedure can have more than one returned table ) E.g. If you use a datareader you can switch to the next next result.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Jeff Papiez - MSFT wrote:

Are you looking for something like this:

using (SqlConnection cxn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial ();
}

Thank you very much, Jeff.

|||

Jens K. Suessmeyer wrote:

If the procedure provides more than one resultsset, you will have to switch between the resultsets to retrieve the resultset you want to get. ( As a procedure can have more than one returned table ) E.g. If you use a datareader you can switch to the next next result.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Jens, thanks a lot.

Wednesday, March 21, 2012

How to get the current User when using a general connection user

I have a VB.Net app and a SQL Server 2005 database. Users must login to use
the application, and I have an Employee table to store their details.
However, I use a common user ID to connect to the database (for reasons I
won't go into here).
My problem is, some of my triggers need to know who the current user is, and
of course I can't use the current connection information to get this as I
always get the common user ID.
Does anyone have a technique to solve this dilema? Maybe some way to set a
variable or something when I connect so that I can determine which user has
initiated the connection?You can use application roles to achieve that. Works something like this:
a) Every user has a Windows account using Windows Authentication
b) When they run the application you enable the application role
c) Inside the application's session you can look at what the username is,
including in triggers, using suser_sname()
Hope this helps,
Ben Nevarez, MCDBA, OCP
Database Administrator
"David" wrote:

> I have a VB.Net app and a SQL Server 2005 database. Users must login to us
e
> the application, and I have an Employee table to store their details.
> However, I use a common user ID to connect to the database (for reasons I
> won't go into here).
> My problem is, some of my triggers need to know who the current user is, a
nd
> of course I can't use the current connection information to get this as I
> always get the common user ID.
> Does anyone have a technique to solve this dilema? Maybe some way to set a
> variable or something when I connect so that I can determine which user ha
s
> initiated the connection?
>

Monday, March 12, 2012

How to get rid of the Database Login window ?

Hi, I'm a newbie in VB.Net, need some help here. I'm generating a report and view it in a win app, which is in VB.Net. I've specified the database logon info by the following code:

*************************************************
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
Dim crReportDocument As New cr1()
With crConnectionInfo
.ServerName = "mydb"
.UserID = "myuserid"
.Password = "mypassword"
End With

CrTables = crReportDocument.Database.Tables

For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next

CrystalReportViewer1.ReportSource = crReportDocument

End Sub
*****************************************************

It's an Oracle DB and just one table, suppose to be very simple. But whenever the app starts, this "Database Login" window always opens first, asking for server info, db info, user name and password. Actually if I click "Cancel", the report still get generated. So how to get rid of this annoying "Database Login" window?

My second question is, how to automatically send this report to printer? I know in VB6 you just say action=1. Unfortunately this thing doesn't work in .Net any more.

Thanks!Just look through CrystalReport knowledgebase, seems that this is a known issue. Refer to this article:
http://support.businessobjects.com/library/kbase/articles/c2010461.asp

Is there already a fix for this ?|||Figured this out by carefully reading this article: http://support.businessobjects.com/library/kbase/articles/c2010461.asp

The Form_new method has to be overwritten, adding some customized initialization, where ser/uid/pass can be specified.

**** I just took it for granted to do it in Form_load...

Wednesday, March 7, 2012

How to get NTEXT data via SP to vb.net app?

i have a table with ntext field and i need to get some fields including the
ntext value to a vb.net application (vs2003)
i have this routine in vb:
Public Function GetMsgs2Email() As DataTable
Dim da As New SqlDataAdapter
Dim result As New DataTable
Try
cmdSelect.CommandText = "SP_name_here"
cmdSelect.CommandType = CommandType.StoredProcedure
da.SelectCommand = cmdSelect
da.Fill(result)
Return result
Catch ex As SqlException
EDTUtils.LogFiles.Log(ex)
Catch ex As Exception
EDTUtils.LogFiles.Log(ex)
End Try
Return Nothing
End Function
How to write the SP that will return as a result set the ntext value with
other fields?
any other techniques will do as well
thanks in advance
raficreate proc dbo.boo as
select ntext_field, someotherfield, anotherone
from dbo.sometable s
where s.somefield=somevalue
"Rafi" <Rafi@.discussions.microsoft.com> wrote in message
news:5BEDBDC2-D19C-4F03-BEFE-391CA4696768@.microsoft.com...
>i have a table with ntext field and i need to get some fields including the
> ntext value to a vb.net application (vs2003)
> i have this routine in vb:
> Public Function GetMsgs2Email() As DataTable
> Dim da As New SqlDataAdapter
> Dim result As New DataTable
> Try
> cmdSelect.CommandText = "SP_name_here"
> cmdSelect.CommandType = CommandType.StoredProcedure
> da.SelectCommand = cmdSelect
> da.Fill(result)
> Return result
> Catch ex As SqlException
> EDTUtils.LogFiles.Log(ex)
> Catch ex As Exception
> EDTUtils.LogFiles.Log(ex)
> End Try
> Return Nothing
> End Function
> How to write the SP that will return as a result set the ntext value with
> other fields?
> any other techniques will do as well
> thanks in advance
> rafi