Click here to Skip to main content
15,906,766 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# and Exceptions Pin
theJazzyBrain26-Jun-03 12:27
theJazzyBrain26-Jun-03 12:27 
GeneralCalling a webservice from a windows service problem Pin
BigAndy26-Jun-03 4:11
BigAndy26-Jun-03 4:11 
General[Q]TabControl,TabPage and Context Menu. Pin
colormex26-Jun-03 3:57
colormex26-Jun-03 3:57 
GeneralDataBinding in C# Pin
Itanium26-Jun-03 1:56
Itanium26-Jun-03 1:56 
GeneralAccess a panel with shortcuts Pin
Anonymous26-Jun-03 0:29
Anonymous26-Jun-03 0:29 
GeneralAccess toolbar with shortcuts Pin
Anonymous26-Jun-03 0:26
Anonymous26-Jun-03 0:26 
GeneralCustom control not getting focus Pin
paulb25-Jun-03 13:51
paulb25-Jun-03 13:51 
Generalhelp with db connection... Pin
.gonad25-Jun-03 10:00
.gonad25-Jun-03 10:00 
Hi guys, i'm sorry for this post since it's clear i still haven't grasped the big picture of how this works yet, so please forgive my ignorance...i'm still very new to c#.

Can someone explain to me how i can use this code to connect to a database and display records? i'm not worried about the db connectivity, since i have that part working, but i am having a problem understanding how to use this code in sections...

for instance, i want to open a dbconnection, then run a sql query based on user input, then close the connection. The only way i know how to do this is to create ONE method that opens the database, executes the query, then closes it again. I'd rather do it in sections like what i have, but maybe that it isn't the best programming...any input on how i can structure this would be helpful.

thanks. Smile | :)

namespace CreateConnection<br />
{<br />
	public class dbcon<br />
	{<br />
		String _dbString;<br />
<br />
		public dbcon(String _dbString)<br />
		{<br />
			OdbcConnection dbConnect = new OdbcConnection(_dbString);<br />
		}<br />
<br />
		public void dbopen()<br />
		{<br />
			dbConnect.Open();<br />
		}<br />
<br />
		public void dbquery(String _dbquery)<br />
		{<br />
			String output = "";<br />
<br />
			OdbcCommand cmd = new OdbcCommand("",dbConnect);<br />
			cmd.CommandText = _dbquery;<br />
			OdbcDataReader dr = cmd.ExecuteReader();<br />
<br />
			while(dr.Read())<br />
			{<br />
				for(int i=0;i<dr.FieldCount;i++)<br />
				{<br />
					output = output + dr.GetValue(i) + ",";<br />
				}<br />
				output = output + "\r";<br />
			}<br />
<br />
			dr.Close();<br />
		}<br />
<br />
		public void dbclose()<br />
		{<br />
			dbConnect.Close();<br />
		}<br />
	}<br />
}


.gonad.
GeneralRe: help with db connection... Pin
.gonad25-Jun-03 17:33
.gonad25-Jun-03 17:33 
GeneralLocationChanged and Move events Pin
Arun Bhalla25-Jun-03 9:54
Arun Bhalla25-Jun-03 9:54 
GeneralWhere to START Pin
isriniv25-Jun-03 9:08
isriniv25-Jun-03 9:08 
GeneralRe: Where to START Pin
Chris Austin25-Jun-03 11:07
Chris Austin25-Jun-03 11:07 
GeneralRe: Where to START Pin
Tomas Petricek25-Jun-03 12:53
Tomas Petricek25-Jun-03 12:53 
GeneralBinding DataGrid Column BackColor Property to a DataBase Field Pin
devmaximus25-Jun-03 7:50
devmaximus25-Jun-03 7:50 
GeneralUsing MSHFlexgrid in C# Pin
Hoang Dung25-Jun-03 7:49
Hoang Dung25-Jun-03 7:49 
GeneralRe: Using MSHFlexgrid in C# Pin
Khang Nguyen25-Jun-03 9:11
Khang Nguyen25-Jun-03 9:11 
GeneralRe: Using MSHFlexgrid in C# Pin
Itanium26-Jun-03 2:01
Itanium26-Jun-03 2:01 
GeneralRe: Using MSHFlexgrid in C# Pin
dynamic27-Jun-03 23:51
dynamic27-Jun-03 23:51 
GeneralScaling the HTML page Pin
JasperHotmail25-Jun-03 6:04
JasperHotmail25-Jun-03 6:04 
GeneralRe: Scaling the HTML page Pin
John Fisher25-Jun-03 7:24
John Fisher25-Jun-03 7:24 
GeneralRe: Scaling the HTML page Pin
JasperHotmail25-Jun-03 8:11
JasperHotmail25-Jun-03 8:11 
QuestionInheritance Picker Dialog/Form Unreadable! Anyone? Pin
Khang Nguyen25-Jun-03 5:52
Khang Nguyen25-Jun-03 5:52 
QuestionDisplay Line Number in C# Code Editor? Pin
Khang Nguyen25-Jun-03 5:45
Khang Nguyen25-Jun-03 5:45 
AnswerRe: Display Line Number in C# Code Editor? Pin
monrobot1325-Jun-03 6:28
monrobot1325-Jun-03 6:28 
GeneralRe: Display Line Number in C# Code Editor? Pin
Khang Nguyen25-Jun-03 6:35
Khang Nguyen25-Jun-03 6:35 

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.