Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
GeneralRe: Voting System in C# Pin
Pete O'Hanlon10-Dec-17 22:47
mvePete O'Hanlon10-Dec-17 22:47 
AnswerRe: Voting System in C# Pin
OriginalGriff10-Dec-17 23:32
mveOriginalGriff10-Dec-17 23:32 
GeneralRe: Voting System in C# Pin
Mycroft Holmes10-Dec-17 23:39
professionalMycroft Holmes10-Dec-17 23:39 
GeneralRe: Voting System in C# Pin
OriginalGriff10-Dec-17 23:43
mveOriginalGriff10-Dec-17 23:43 
GeneralRe: Voting System in C# Pin
phil.o11-Dec-17 18:02
professionalphil.o11-Dec-17 18:02 
QuestionGeneric type passed into method question Pin
User987439-Dec-17 20:44
professionalUser987439-Dec-17 20:44 
AnswerRe: Generic type passed into method question Pin
OriginalGriff9-Dec-17 22:32
mveOriginalGriff9-Dec-17 22:32 
QuestionRe: Generic type passed into method question Pin
User9874310-Dec-17 0:49
professionalUser9874310-Dec-17 0:49 
This is a big help! I've been working on it for hours. I'm working on some existing code that I'm supposed to make work with both OleDbConnection as well as SqlConnection.

It's more of a training exercise for me, because it looks like it's going to take a lot of time to convert all of the db methods to use either connection.

So right now, I have an OleDbConnection, like so:

private OleDbConnection DataConnection ( int index_of_mydatafile )
{
    string dbpath = MyDataFiles[ index_of_mydatafile ];

    string conn_string = OledbProvider(dbpath) + "data source=" + dbpath;

    Debug.WriteLine ( conn_string );

    return new OleDbConnection ( conn_string );

}

The connection is just be declared and instantiated in a using statement like this:

using ( OleDbConnection dbConnection = DataConnection ( index_of_mydatafile ) )
			using ( OleDbCommand dbCommand = new OleDbCommand ( sql , dbConnection ) )
			using ( OleDbDataAdapter adapter = new OleDbDataAdapter ( dbCommand ) )

So the command object is actually opening the connection later. To get this working, I tried this, but I'm stuck at the new declaration, which is causing an error, presumably because I need to cast the T maybe? I'm just pulling things out of thin air now. lol
private T DataConnection<T> ( T db_conn_obj , int index_of_mydatafile ) where T : System.Data.Common.DbConnection
		{
			string dbpath = MyDataFiles[ index_of_mydatafile ];
			string provider = OledbProvider ( dbpath );
			string conn_string =  provider + "data source=" + dbpath;

			Debug.WriteLine ( conn_string );

			if ( provider == "" )
			{
				conn_string = @"Data Source= xxxx\xxxx;Initial Catalog=xxxx;Integrated Security=SSPI;Connect Timeout=5;ConnectRetryCount=0;ApplicationIntent=ReadWrite;"
			}
	
			return new T ( conn_string );
		}

AnswerRe: Generic type passed into method question Pin
OriginalGriff10-Dec-17 0:57
mveOriginalGriff10-Dec-17 0:57 
GeneralRe: Generic type passed into method question Pin
User9874310-Dec-17 1:05
professionalUser9874310-Dec-17 1:05 
GeneralRe: Generic type passed into method question Pin
OriginalGriff10-Dec-17 1:49
mveOriginalGriff10-Dec-17 1:49 
AnswerRe: Generic type passed into method question Pin
Eddy Vluggen10-Dec-17 3:03
professionalEddy Vluggen10-Dec-17 3:03 
GeneralRe: Generic type passed into method question Pin
User9874310-Dec-17 18:41
professionalUser9874310-Dec-17 18:41 
GeneralRe: Generic type passed into method question Pin
Eddy Vluggen11-Dec-17 2:34
professionalEddy Vluggen11-Dec-17 2:34 
AnswerRe: Generic type passed into method question Pin
Gerry Schmitz10-Dec-17 1:04
mveGerry Schmitz10-Dec-17 1:04 
Question2 Active Directory Questions Pin
Kevin Marois7-Dec-17 9:42
professionalKevin Marois7-Dec-17 9:42 
AnswerRe: 2 Active Directory Questions Pin
Dave Kreskowiak7-Dec-17 13:11
mveDave Kreskowiak7-Dec-17 13:11 
GeneralRe: 2 Active Directory Questions Pin
Kevin Marois8-Dec-17 5:13
professionalKevin Marois8-Dec-17 5:13 
GeneralRe: 2 Active Directory Questions Pin
Dave Kreskowiak8-Dec-17 7:29
mveDave Kreskowiak8-Dec-17 7:29 
AnswerRe: 2 Active Directory Questions Pin
Eddy Vluggen7-Dec-17 14:20
professionalEddy Vluggen7-Dec-17 14:20 
QuestionHow can I add multiple headers in a ListView Control winforms c#? Pin
Dionisio Huerta Rosario7-Dec-17 6:25
Dionisio Huerta Rosario7-Dec-17 6:25 
AnswerRe: How can I add multiple headers in a ListView Control winforms c#? Pin
Gerry Schmitz7-Dec-17 20:41
mveGerry Schmitz7-Dec-17 20:41 
AnswerRe: How can I add multiple headers in a ListView Control winforms c#? Pin
Ralf Meier8-Dec-17 1:06
mveRalf Meier8-Dec-17 1:06 
QuestionDynamic HTML from Code Behind Pin
warren8r7-Dec-17 5:16
warren8r7-Dec-17 5:16 
AnswerRe: Dynamic HTML from Code Behind Pin
Gerry Schmitz7-Dec-17 6:16
mveGerry Schmitz7-Dec-17 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.