Click here to Skip to main content
16,005,281 members
Home / Discussions / C#
   

C#

 
GeneralRe: IOExpection error using Streamreader and FileStream Pin
yefeng_law21-Sep-08 7:24
yefeng_law21-Sep-08 7:24 
AnswerRe: IOExpection error using Streamreader and FileStream Pin
zafersavas21-Sep-08 0:59
zafersavas21-Sep-08 0:59 
Questionhow to crate an class from the xsd Pin
prasadbuddhika20-Sep-08 18:47
prasadbuddhika20-Sep-08 18:47 
AnswerRe: how to crate an class from the xsd Pin
Mirko198024-Sep-08 4:16
Mirko198024-Sep-08 4:16 
Questionnewbee question Pin
Rafone20-Sep-08 16:08
Rafone20-Sep-08 16:08 
AnswerRe: newbee question Pin
Caio Kinzel Filho20-Sep-08 16:28
Caio Kinzel Filho20-Sep-08 16:28 
GeneralRe: newbee question Pin
Rafone20-Sep-08 16:56
Rafone20-Sep-08 16:56 
GeneralRe: newbee question Pin
Caio Kinzel Filho20-Sep-08 17:52
Caio Kinzel Filho20-Sep-08 17:52 
Hi,
To do that: your other class will need to have a "static" method (do not need a instance - google it if needed), and problably you would have to pass the grid to the function.

Anyway, I was think that's is not the best solution, I would like to give some tips:
- Do not use hard-coded connection string. Put the connection string in app.config and reference from there.
- Do not modularize so much as to make your module dependable of your form.
- Maybe try something like that, just a quick implementation, and easy to use:

public class DatabaseAccess
{
    public static DataTable OpenQuery(string query)
    {
        OleDbCommand cmd;
        OleDbConnection cnn;
        OleDbDataAdapter da;
        DataSet ds;
        DataTable table;

        try
        {
            cnn = new OleDbConnection(YOUR_CONNECTION_STRING);
            cmd = new OleDbCommand(query, cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            da = new OleDbDataAdapter(cmd);
            ds = new DataSet();
            da.Fill(ds);
            table = ds.Tables[0];
            cnn.Close();
            cnn.Dispose();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        return table;
    }
}


And use it like:

grid1.DataSource = DatabaseAccess.OpenQuery("SELECT ... FROM...");


Regards

Intelligence is almost useless for those who have nothing else!

Email: caiokf@gmail.com

GeneralRe: newbee question Pin
Rafone20-Sep-08 18:34
Rafone20-Sep-08 18:34 
GeneralRe: newbee question Pin
Caio Kinzel Filho20-Sep-08 22:52
Caio Kinzel Filho20-Sep-08 22:52 
AnswerOT Pin
Harvey Saayman20-Sep-08 21:28
Harvey Saayman20-Sep-08 21:28 
QuestionCustom DataGridViewCell data binding question. Pin
Bliedtke20-Sep-08 15:49
Bliedtke20-Sep-08 15:49 
AnswerRe: Custom DataGridViewCell data binding question. Pin
Bliedtke21-Sep-08 10:19
Bliedtke21-Sep-08 10:19 
QuestionExtract certain text from a html page. Pin
Buckleyindahouse20-Sep-08 13:31
Buckleyindahouse20-Sep-08 13:31 
AnswerRe: Extract certain text from a html page. Pin
Jan Sommer20-Sep-08 23:43
Jan Sommer20-Sep-08 23:43 
GeneralRe: Extract certain text from a html page. Pin
Buckleyindahouse21-Sep-08 3:24
Buckleyindahouse21-Sep-08 3:24 
GeneralRe: Extract certain text from a html page. Pin
Jan Sommer21-Sep-08 3:40
Jan Sommer21-Sep-08 3:40 
GeneralRe: Extract certain text from a html page. Pin
Buckleyindahouse21-Sep-08 6:21
Buckleyindahouse21-Sep-08 6:21 
AnswerRe: Extract certain text from a html page. Pin
Bliedtke21-Sep-08 10:35
Bliedtke21-Sep-08 10:35 
GeneralRe: Extract certain text from a html page. Pin
Bliedtke21-Sep-08 10:39
Bliedtke21-Sep-08 10:39 
AnswerRe: Extract certain text from a html page. Pin
Bliedtke21-Sep-08 11:48
Bliedtke21-Sep-08 11:48 
QuestionHow can I access to an item in a solution folder ? Pin
Mohammad Dayyan20-Sep-08 11:32
Mohammad Dayyan20-Sep-08 11:32 
AnswerRe: How can I access to an item in a solution folder ? Pin
Caio Kinzel Filho20-Sep-08 14:55
Caio Kinzel Filho20-Sep-08 14:55 
GeneralRe: How can I access to an item in a solution folder ? Pin
Mohammad Dayyan21-Sep-08 3:35
Mohammad Dayyan21-Sep-08 3:35 
GeneralRe: How can I access to an item in a solution folder ? Pin
Caio Kinzel Filho21-Sep-08 7:20
Caio Kinzel Filho21-Sep-08 7:20 

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.