|
-
Aug 16th, 2010, 12:43 AM
#41
PowerPoster
Re: Database connection issue
can you post the code you currently have? it would help
-
Sep 6th, 2010, 08:16 AM
#42
Thread Starter
Frenzied Member
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.
-
Sep 6th, 2010, 08:24 AM
#43
PowerPoster
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
-
Sep 14th, 2010, 07:58 AM
#44
Thread Starter
Frenzied Member
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!!! 
-
Sep 14th, 2010, 09:44 AM
#45
PowerPoster
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
-
Dec 7th, 2010, 03:31 AM
#46
Thread Starter
Frenzied Member
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.
-
Dec 7th, 2010, 04:25 AM
#47
PowerPoster
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
-
Dec 7th, 2010, 05:05 AM
#48
Thread Starter
Frenzied Member
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.
-
Dec 7th, 2010, 05:07 AM
#49
PowerPoster
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.
-
Dec 7th, 2010, 05:15 AM
#50
Thread Starter
Frenzied Member
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.
-
Dec 7th, 2010, 05:19 AM
#51
PowerPoster
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.
-
Dec 7th, 2010, 05:24 AM
#52
Thread Starter
Frenzied Member
Re: Database connection issue
Last edited by firoz.raj; Dec 8th, 2010 at 12:15 AM.
-
Dec 7th, 2010, 08:36 AM
#53
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
-
Dec 8th, 2010, 12:13 AM
#54
Thread Starter
Frenzied Member
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.
-
Dec 8th, 2010, 08:21 AM
#55
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
-
Dec 9th, 2010, 12:43 AM
#56
Thread Starter
Frenzied Member
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+ ' " ;
-
Dec 9th, 2010, 01:50 AM
#57
Junior Member
Re: Database connection issue
 Originally Posted by firoz.raj
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.
-
Dec 9th, 2010, 08:19 AM
#58
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|