Showing posts with label visual. Show all posts
Showing posts with label visual. Show all posts

Friday, March 30, 2012

How to get the value of a SQL query before binding it to DataGrid?

I am using C#.Net, Visual web Developer, SQL server 2000.

I have a SQL query which I am binding it to a DataGrid.

SQL : "SELECT ord_number, ord_ID, ord_split, ord_Name, ETD_Date, OSP_FSD FROM ORDERS"

In My DataGrid I have a dynamic databound column.

I am able to bind one column to this databound column using following code.

BoundColumn ETDDate = new BoundColumn();
ETDDate.HeaderText = "ETD Date";
ETDDate.DataField = "OSP_FSD";
mygrid2.Columns.AddAt(ETDDate);

but now I want to bind this databound column based on the following criteria to two different database columns.

if(ord_split = 1)
{
ETDDate.DataField = "OSP_FSD";
}
else
{
ETDDate.DataField = "ETD_Date";
}

How to get value of ord_split before binding SQL to teh DataGrid? i.e I just want to take value of ord_split and not all the values of SQL.

Please Help!

HI~

ord_split if different in each row but if you change ETDDate.DataField it will affect all rows.

I am afraid you just want to display OSP_FSD for the rows " ord_split =1 " or ETD_Date if not.

If so you can change the text inGridView'sRowDataBound Event.

Wednesday, March 28, 2012

How to get the returning value of a stored procedure?

Hi everyone!
I am new to sql server 2005 and visual studio 2005.

I have the following simple stored procedure that checks if a user exists:
-------------------------------
ALTER PROCEDURE [dbo].[sp_Users_AlreadyExists]

@.UserName varchar(256)
AS
BEGIN
SET NOCOUNT ON;


IF (EXISTS (SELECT UserName FROM dbo.Users WHERE LOWER(@.UserName) = LoweredUserName ))
RETURN(1)
ELSE
RETURN(0)
END
-------------------------------

I use the following code to execute the procedure on visual studio:
-------------------------------
.
.
.
cmdobj As SqlCommand
cmdobj = New SqlCommand(sp_Users_AlreadyExists, connobj)
cmdobj.CommandType = CommandType.StoredProcedure
cmdobj.Parameters.AddWithValue("@.UserName", "blablalala")
cmdobj.ExecuteNonQuery()
cmdobj.Dispose()
connobj.Close()
.
.
.
-------------------------------

I expected that cmdobj.ExecuteNonQuery() would return 1 if the userblablab exists or 0 if the user doesnt, but it just return -1 (i thinkbecause no row was affected)

Does anyone knows how to retrieve the value that my stored procedure returns?

Thanx in advance!

cmdobj.parameters.add("@.RETURN_VALUE",sqldbtype.int).direction=returnvalue

Then check the parameter value after the execute like:

dim val as integer=cmdobj.parameters("@.RETURN_VALUE").value

sql

Monday, March 19, 2012

How to get Server Name? (Using VC++, MSSQL & ODBC)

Hi. Is there a way in order to get the Server name using MSSQL ODBC in Visual C++? Here's my code:

CString wstr_connect ;
wstr_connect.Format( "DSN=%s;UID=%s;PWD=%s", gstr_DBName, gstr_UserID, gstr_Password ) ;
CDatabase mydb ;
BOOL ret = mydb.OpenEx( wstr_connect, CDatabase::noOdbcDialog ) ;
CString info = mydb.GetConnect( ) ;

GetConnect only returns the database name, user ID, password and WSID. How do i get the server name?

Thanks in advance!I'm not using CDatabase at the moment, but check out this page:
http://www.cppdoc.com/example/mfc/classdoc/MFC/CDatabase.html

There is a function called GetConnectInfo(); maybe that can help you?|||I think it depends on the driver you are using. I think one problem you are having is that you are not actually providing a "DBName"; your Format function has a string with "DSN=" which I am nearly certain means that you are using a datasource. The server is specified in the datasource.

Note that the CDatabase class has a member m_hdbc; it can be used to get a handle for use with the SDK version of ODBC. Look at the sample code for CDatabase::m_hdbc; it might lead you to a good answer.|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatP|||Maybe I'm missing something, but couldn't you just use:SELECT @.@.servername-PatPI don't know how to do that in VC; cwong asked how to do it "using MSSQL ODBC in Visual C++".

Monday, March 12, 2012

How to Get RS Tools for Visual Studio 2003?

The overall question: How do I get the Reporting Services tools for Visual
Studio 2003 if my web hosting company owns the SQL Server?
I am a lone developer with a laptop and a web hosting company. I have Visual
Studio 2003 installed on my laptop (Windows XP Pro). My web host provides me
with .NET, SQL Server 2000, and now Reporting Services. I want to begin to
learn and use Reporting Services.
In searching Microsoft's web site, it seems that I can only obtain the tools
that go into Visual Studio to develop RS reports if I have my own SQL Server
2000. I own a copy of SQL Server 2000 Professional, but I cannot install it
on XP Pro. It requires a server version of Windows. I do have MSDE
installed, but Reporting Services (RSEval.exe) refuses to install on this
version. I don't have access to high priced things like an MSDN universal or
enterprise subscription. I don't qualify for academic versions.
There must be a way for developers like me to get the tools necessary to
create these reports. Any ideas?You do not need to install the server to use the tools (setup will warn you
but you can ignore it). The evaluation version should work fine for you.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Rick" <rrgrimm@.hotmail.com> wrote in message
news:OjYVHZ2pEHA.2696@.TK2MSFTNGP15.phx.gbl...
> The overall question: How do I get the Reporting Services tools for Visual
> Studio 2003 if my web hosting company owns the SQL Server?
> I am a lone developer with a laptop and a web hosting company. I have
> Visual Studio 2003 installed on my laptop (Windows XP Pro). My web host
> provides me with .NET, SQL Server 2000, and now Reporting Services. I want
> to begin to learn and use Reporting Services.
> In searching Microsoft's web site, it seems that I can only obtain the
> tools that go into Visual Studio to develop RS reports if I have my own
> SQL Server 2000. I own a copy of SQL Server 2000 Professional, but I
> cannot install it on XP Pro. It requires a server version of Windows. I do
> have MSDE installed, but Reporting Services (RSEval.exe) refuses to
> install on this version. I don't have access to high priced things like an
> MSDN universal or enterprise subscription. I don't qualify for academic
> versions.
> There must be a way for developers like me to get the tools necessary to
> create these reports. Any ideas?
>

How to get Row Numbers from SQL Express 2005 query?

Hi,

I'm using SQL Express 2005 and VIsual Studio 2005, and this sounds like it should be easy. I'm trying to return the row numbers of my queries, but if I use the Row_Number() command I get the following error:

"The OVER SQL construct or statement is not supported."

So, is Row_Number() not supported in SQL Express 2005? If not, how can I return row numbers with my queries? Or, more specifically, how can I return a limited result set from a query (i.e. Return only row number 10-20)?

My current command is as follows:

SELECT (SELECT Row_Number()OVER (ORDER BY UserName)As RowNumber), *
FROM Users
ORDER BY UserName

Thanks for any advice you can offer!


like this

With Cust AS
( SELECT CustomerID, CompanyName,
ROW_NUMBER() OVER (order by CompanyName) as RowNumber
FROM Customers )
select *
from Cust
Where RowNumber Between 20 and 30

Hope this helps

|||

SELECT ROW_NUMBER() OVER (ORDER BY ProductID) as RowNumber,ProductID, ProductName, UnitPrice FROM Products WHERE RowNumber BETWEEN 20 AND 30;

|||

Thank you both for your replies. I'm sorry, I think I my question may have been a bit misleading. I know that you can return a limited result set by using the statements you have provided, but the error message I am getting is as follows:

"The OVER SQL construct or statement is not supported."

Both your suggestions use the OVER construct, and this does not appear to be supported bySQL Server Express 2005. If I run your suggested queries inVisual Studio 2005 I get the aforementioned error and the query will not run (though the SQL validation check says it's fine).

So, is the "Row_Number() OVER" command supported by SQL Express 2005 or not? If not, what other ways can I return a limited result set?

|||

i think you are using the designer, go in the sql server management studio and to this

Select File / New / Query and type your queries in the editing window instead.

Hope this helps

|||

Run this in SQL SERVER 2005 Management Studio Express:

EXEC sp_dbcmptlevel yourDataBase

If the current compatibility level of your database is 80, then run this:

EXEC sp_dbcmptlevel yourDataBase, 90


You need the compatibility level at 90 to run the Row_Number() OVER() query and other new features.

|||

Hi Limno,

That sounds promising. I've tried getting my website database into SQL Server Management Studio Express in the past but without success. My database is held as a .MDF file within my project - is there a way of importing this directly into Management Studio? The "Connect To Server" dialog displayed on startup does not allow me to browse to a specific .MDF file, and the File -> Open dialog has no option to open .MDF files.

Thanks

|||

I just found out how to import an MDF here:

http://forums.asp.net/p/1147899/1871779.aspx#1871779

And my database shows a compatibility rating of 90. Using the Row_Number() command works within SQL Server Management Express Studio! In that case, how can I perform a query in Visual Studio 2005 that uses this command if Visual Studio does not support this command?

I'm using strongly typed Table Adapters and Data Tables using the DAL component in Visual Studio. Is it impossible? If not, can I at least perform this query programmatically (C#) and cast the results to my strongly typed Data Table? If it can be done programmatically, does anyone have any examples of how to do this?

Thanks again!

|||

In Visual Studio 2005, you will see that not support message. Have you tried to ingnore it and see what will happen? It seems is should work fine. Another way, you can wrap your query in a Stored Procedure to work with.

Friday, March 9, 2012

How to get query execution time of an MS SQL Query in Visual basic

please let me know How to get query execution time of an MS SQL Query
in Visual basic
If you are executing the query from vba, create a timer (using
GetTickcount from the Windows API or something similar). Record the
start time at the beginning of the query, and the stop time after it
completes. Compute the total time elapsed.
--Mary
On 14 Sep 2004 23:46:21 -0700, rajeevmc@.yahoo.com (Rajeev M C) wrote:

>please let me know How to get query execution time of an MS SQL Query
>in Visual basic

How to get query execution time of an MS SQL Query in Visual basic

please let me know How to get query execution time of an MS SQL Query
in Visual basicIf you are executing the query from vba, create a timer (using
GetTickcount from the Windows API or something similar). Record the
start time at the beginning of the query, and the stop time after it
completes. Compute the total time elapsed.
--Mary
On 14 Sep 2004 23:46:21 -0700, rajeevmc@.yahoo.com (Rajeev M C) wrote:
>please let me know How to get query execution time of an MS SQL Query
>in Visual basic