Page 2 of 2 FirstFirst 12
Results 41 to 58 of 58

Thread: Database connection issue

  1. #41
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    can you post the code you currently have? it would help

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #42

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    Can You tell me ?How should I write DataBase Path in the settings area af the properties ?let me know please.When tried to Click on settings nothing happens.so let me know How should I assign path there???.

    Thx in Advance.
    Last edited by firoz.raj; Sep 29th, 2010 at 08:55 AM.

  3. #43
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    well typically a connectionstring looks like this:

    Data Source=computerName\SQLSERVERINSTANCE;Initial Catalog=Databasename;Trusted_Connection=true;

    replace data source and initial catalog values appropriately.

    if you are NOT using SQL Server Express, then the data source is typically just a local pointer example:

    local
    (local)
    .

    if you are using SQL Server Express, then the instance name is SQLExpress:

    .\SQLExpress

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #44

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    well typically a connectionstring looks like this:

    Data Source=computerName\SQLSERVERINSTANCE;Initial Catalog=Databasename;Trusted_Connection=true;

    replace data source and initial catalog values appropriately.

    if you are NOT using SQL Server Express, then the data source is typically just a local pointer example:

    local
    (local)
    .

    if you are using SQL Server Express, then the instance name is SQLExpress:

    .\SQLExpress
    but i am using DataBase Ms Access 2007.let me know please!!!

  5. #45
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    sure. in which case the connectionstring differs.

    you need to import the System.Data and System.Data.OleDB namespace to gain access to the OleDBConnection and OleDBCommand classes which will do what you pretty much want and operate similarly to the Sql classes.

    www.connectionstrings.com contains all the possible connection strings.

    http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #46

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    I Simple want if specific Text exists in the fields( Identity) in the specific table(IdentityTab). Method needs to return true . otherwise false .i did flow . but I don’t know how should I Achieve the following Method ??? Using C# Code. which I did in Vsd . Using OleDbCommand object and the OleDbDataReader in c#
    Code:
     public bool Identification(string identifier) {
               
                    using (OleDbConnection conn=new OleDbConnection(_path)){
                        conn.Open();
                        using (OleDbCommand Cmd = new OleDbCommand(_path)){                    
                            Cmd.CommandText = "Select identityNo from identityTab";
                            how should i check specific text in a fields of Specific Table ???.
                            if found 
                            return true ; 
                            
                        }
                    
                    return false;
                }
    Last edited by firoz.raj; Dec 7th, 2010 at 05:06 AM.

  7. #47
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    well you are almost there. in this case, you should use oleDbDataReader which is a fast forward only reader. so executeReader on your OleDbCommand, which returns you an OleDbDataReader, then see if there is a record returned by calling it's Read() method, which returns a bool.

    an example and documentation of the class:

    http://msdn.microsoft.com/en-us/libr...er(VS.71).aspx

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #48

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    I need using vsd logic . let me know . how should I Achieve it ???.How should I check Specific text in the field of the table .
    Last edited by firoz.raj; Dec 15th, 2010 at 08:14 AM.

  9. #49
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    looks like homework to me. a link was given which explains how the class works, with an example. you need to read the documentation and understand it to implement your VSD logic.

    hint: the reader has an index you can specify to read a field value.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  10. #50

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    [Quote]looks like homework to me. a link was given which explains how the class works, with an example. you need to read the documentation and understand it to implement your VSD logic.

    hint: the reader has an index you can specify to read a field value.

    [FONT="Comic Sans MS" How should I check specific Index Using Reader Property ??????????? .[/FONT]
    Last edited by firoz.raj; Dec 7th, 2010 at 08:57 AM.

  11. #51
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Database connection issue

    by specifying the indexing characters. or you can use GetString method to get a string value of the specified column index.

    example:

    reader[ColumnIndexHere]

    this will read the value of the specified column index

    however your code is still wrong. OleDbDataReader is not an instantiable class.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  12. #52

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    Still the same.
    Last edited by firoz.raj; Dec 8th, 2010 at 12:15 AM.

  13. #53
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Database connection issue

    Calm down. You're talking like freaking Yoda, and panicking at the same time and it's not helping the situation.

    Think for a moment about the code you posted and why it doesn't work (by the way, that's two trout slaps for not mentioning the error message.)

    You pass in a parameter "identifier" ... but then never use it any where. Then you use a variable called "identityNo" which is never defined anywhere. AND you use it as the indexor of the reader array. Then you're comparing what I'm assuming to be a numerical field to the boolean value of true.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #54

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    you use a variable called "identityNo" which is never defined anywhere. AND you use it as the indexor of the reader array. Then you're comparing what I'm assuming to be a numerical field to the boolean value of true.

    I Have tried but still I am getting the same error !!!.
    Code:
      public bool Identification(string identifier){        
                using (OleDbConnection conn = new OleDbConnection(_path)){            
                conn.Open();
                    using (OleDbCommand Cmd = new OleDbCommand(_path)){
                        Cmd.CommandText = "Select identityNo from identityTab where identityTab.IdentityNo="+identifier ;
                         return true;                      
                              }                          
                        return false;               
                    }
                 }
    Last edited by firoz.raj; Dec 8th, 2010 at 12:36 AM.

  15. #55
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Database connection issue

    1) Stop yelling... that's not going to accomplish anything other than offending those who are doing their best to help.
    2) what is _path? I'm guessing that it is your connection string, right? Then you pass it to your connection (which you are - good) but you do NOT pass it to your command object.
    3) The only things you should be passing to your command object is your connection and your sql statement. at a minimum, you should be passing the connection (but not the _path).
    4) You've created the command object set the command text, but never execute it.
    5) You may want to consider reading through our Database FAQs and Tutorials there's some good stuff in there, including the basics of how to talk to your database. And how to use parameters too.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #56

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Database connection issue

    At first Identifier is a text .when I write single quote .i am getting error Newline is Constant !!!.

    Cmd.CommandText = "Select identityNo from identityTab where identityTab.IdentityNo="' +identifier+ ' " ;

  17. #57
    Junior Member
    Join Date
    Mar 2009
    Posts
    24

    Re: Database connection issue

    Quote Originally Posted by firoz.raj View Post
    At first Identifier is a text .when I write single quote .i am getting error Newline is Constant !!!.

    Cmd.CommandText = "Select identityNo from identityTab where identityTab.IdentityNo="' +identifier+ ' " ;
    I see one issue that is very obvious.

    Code:
    Cmd.CommandText = String.Concat( "Select identityNo from identityTab where identityTab.IdentityNo='", identifier, "'");
    This should solve the very obvious issue. Always double check when combining strings if you require an ' remember to have it inside the ". As you can see in your example, neither are within the realm of the quotations and therefore you should be receiving an error.

  18. #58
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Database connection issue

    To be perfectly honest, even the ' isn't necessary. If it's a number, treat it like a number, not a string.
    Code:
    Cmd.CommandText = String.Concat( "Select identityNo from identityTab where identityTab.IdentityNo=", identifier);
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width