Click here to Skip to main content
15,888,733 members
Home / Discussions / C#
   

C#

 
GeneralMessage Handler Pin
JorcanFyn17-Jun-03 5:35
JorcanFyn17-Jun-03 5:35 
GeneralRe: Message Handler Pin
albean17-Jun-03 5:55
albean17-Jun-03 5:55 
GeneralRe: Message Handler Pin
JorcanFyn17-Jun-03 6:03
JorcanFyn17-Jun-03 6:03 
GeneralDraw in the title of a form Pin
STW17-Jun-03 5:11
STW17-Jun-03 5:11 
GeneralRe: Draw in the title of a form Pin
Dimitris Iliopoulos17-Jun-03 13:42
Dimitris Iliopoulos17-Jun-03 13:42 
GeneralMajor Error Needing Major Help!!! Pin
jesus4u17-Jun-03 4:47
jesus4u17-Jun-03 4:47 
GeneralRe: Major Error Needing Major Help!!! Pin
Dimitris Iliopoulos17-Jun-03 13:46
Dimitris Iliopoulos17-Jun-03 13:46 
GeneralReturning all fields in a database Pin
.gonad17-Jun-03 4:25
.gonad17-Jun-03 4:25 
Hi everyone. (this is my first post to this board, so please forgive me if it doesn't look right).

I am new to c# and i am wondering if someone can help me write a for loop to return all the fields and data in a database. This is the code and it works 100%, but i want it to query the table fields and data dynamically instead of what i have.

<br />
using System;<br />
using Microsoft.Data.Odbc;<br />
using Console = System.Console;<br />
<br />
namespace practice<br />
{<br />
        public class dbconnection<br />
	{<br />
		public void swdata()<br />
		{<br />
			string msg;<br />
			string native;<br />
			string src;<br />
			string sql;<br />
<br />
			try<br />
			{<br />
				string _db = "DRIVER={MySQL ODBC 3.51 Driver};" +<br />
								"SERVER=<server ip>;DATABASE=<db>;" +<br />
								"UID=<user>;PASSWORD=<pwd>;" +<br />
								"OPTION=512";<br />
				OdbcConnection dbconnect = new OdbcConnection(_db);<br />
				dbconnect.Open();<br />
<br />
				OdbcCommand my_cmd = new OdbcCommand("",dbconnect);<br />
<br />
				my_cmd.CommandText = "SELECT * FROM swdata_o";<br />
				OdbcDataReader my_dr;<br />
				my_dr = my_cmd.ExecuteReader();<br />
<br />
				// RETURN ALL FIELDS IN DATABASE - FOR LOOP<br />
				while(my_dr.Read())<br />
				{<br />
					Console.WriteLine(my_dr.GetInt32(0) + "," + my_dr.GetString(1)<br />
						+ "," + my_dr.GetString(2));<br />
				}<br />
				dbconnect.Close();<br />
			}<br />
<br />
			catch(OdbcException odbcCon)<br />
			{<br />
				for(int i=0;i<odbcCon.Errors.Count;i++)<br />
				{<br />
					msg=odbcCon.Errors[i].Message;<br />
					native=odbcCon.Errors[i].NativeError.ToString();<br />
					src=odbcCon.Errors[i].Source;<br />
					sql=odbcCon.Errors[i].SQLState;<br />
				}<br />
			}<br />
		}<br />
	}<br />
<br />
	public class open<br />
	{<br />
		public static void Main(String[] args)<br />
		{<br />
			dbconnection dbcon = new dbconnection();<br />
			dbcon.swdata();<br />
		}<br />
	}<br />
<br />
}<br />


Thanks for your help. Smile | :)
GeneralRe: Returning all fields in a database Pin
.gonad17-Jun-03 6:56
.gonad17-Jun-03 6:56 
GeneralRe: Marshalling Pin
firat kocak17-Jun-03 3:21
firat kocak17-Jun-03 3:21 
GeneralRe: Marshalling Pin
firat kocak17-Jun-03 3:58
firat kocak17-Jun-03 3:58 
GeneralRe: Marshalling Pin
firat kocak17-Jun-03 4:46
firat kocak17-Jun-03 4:46 
GeneralInterop Pin
grv57516-Jun-03 21:48
grv57516-Jun-03 21:48 
GeneralRe: Interop Pin
firat kocak17-Jun-03 1:25
firat kocak17-Jun-03 1:25 
Generalplease help, simple question Pin
wickedclownz16-Jun-03 21:30
wickedclownz16-Jun-03 21:30 
GeneralRe: please help, simple question Pin
Nick Seng16-Jun-03 22:55
Nick Seng16-Jun-03 22:55 
GeneralRe: please help, simple question Pin
wickedclownz16-Jun-03 23:00
wickedclownz16-Jun-03 23:00 
GeneralRe: please help, simple question Pin
Nick Seng16-Jun-03 23:16
Nick Seng16-Jun-03 23:16 
GeneralRe: please help, simple question Pin
wickedclownz16-Jun-03 23:09
wickedclownz16-Jun-03 23:09 
GeneralRe: please help, simple question Pin
shaunAustin17-Jun-03 2:23
shaunAustin17-Jun-03 2:23 
GeneralRe: please help, simple question Pin
Dimitris Iliopoulos17-Jun-03 13:53
Dimitris Iliopoulos17-Jun-03 13:53 
GeneralRe: please help, simple question Pin
obaeyens18-Jun-03 3:49
obaeyens18-Jun-03 3:49 
GeneralDate Sorting of Files Pin
azusakt16-Jun-03 16:26
azusakt16-Jun-03 16:26 
GeneralRe: Date Sorting of Files Pin
reinas16-Jun-03 22:20
reinas16-Jun-03 22:20 
GeneralIntercepting HTML before IE gets it Pin
Anonymous16-Jun-03 15:30
Anonymous16-Jun-03 15:30 

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.