Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2004, 05:29 AM
Authorized User
 
Join Date: Aug 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Baby_programmer Send a message via MSN to Baby_programmer Send a message via Yahoo to Baby_programmer
Default sql query problem

hi!
Please help me i have a fuction that will check that, if there is any value exist in table
as input given.
the fuction i have written is like this but not working:

private int GetShopID(string ShopName)
{
    string connectionString = ConfigurationSettings.AppSettings["conStr"];
    string qry ="SELECT ShopID FROM tblShopInformation where ShopName=@ShopName";
    SqlConnection con= new SqlConnection(connectionString);
    SqlCommand cmd= new SqlCommand(qry,con);
    cmd.Parameters.Add("@ShopName",SqlDbType.NVarChar, 50).Value = ShopName;
    string Shop_ID=qry;
    int ShopID=Convert.ToInt16("Shop_ID");
    if(ShopID>=1)
    {
    Label1.Text="value exist";
    }
    return 0;
}


private void Page_Load(object sender, System.EventArgs e)
        {

            GetShopID("abc");
        }


If there is any other method to check the value in the sql table please
make this kind of fuction for me ..i'll be thankfull.

ashfaq
__________________
Baby Prgrammer
 
Old October 14th, 2004, 07:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Dim bResult As Boolean = False
Dim objConn As New OleDbConnection(ConfigurationSettings.AppSettings( "conStr"))
Dim strSQL As String
Dim strTestValue As String
Dim objCommand As New OleDbCommand

objCommand.Connection = objConn
strSQL = String.Format("SELECT shopid FROM tblShopInformation WHERE (ShopName='{0}');", ShopName)
objCommand.CommandText = strSQL
objCommand.CommandType = CommandType.Text

objConn.Open()
strTestValue = CType(objCommand.ExecuteScalar, String)
objConn.Close()

If Not strTestValue Is Nothing Then
    If strTestValue = ShopName Then
        bResult = True

Sorry for the VB code.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query Problem mike.chary SQL Server 2005 1 September 26th, 2007 06:19 AM
SQL Query problem skarthikk SQL Server 2000 1 August 7th, 2006 02:20 AM
SQL query problem - Need Help Settt Biztalk 0 September 12th, 2005 09:32 AM
Problem in SQL query liorlankri ADO.NET 1 November 8th, 2004 12:37 AM
Sql Query Problem mateenmohd SQL Language 0 January 13th, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.