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

C#

 
GeneralRe: invalid path using process.start method Pin
stephan_0075-Aug-08 1:12
stephan_0075-Aug-08 1:12 
GeneralRe: invalid path using process.start method Pin
stephan_0075-Aug-08 2:41
stephan_0075-Aug-08 2:41 
GeneralRe: invalid path using process.start method Pin
stephan_0075-Aug-08 11:22
stephan_0075-Aug-08 11:22 
AnswerRe: invalid path using process.start method Pin
astanton19785-Aug-08 2:50
astanton19785-Aug-08 2:50 
QuestionWhy the error message like "Object reference not set to an instance" comes.. Pin
Samiullah4-Aug-08 21:46
Samiullah4-Aug-08 21:46 
AnswerRe: Why the error message like "Object reference not set to an instance" comes.. Pin
Mogaambo4-Aug-08 22:09
Mogaambo4-Aug-08 22:09 
GeneralRe: Why the error message like "Object reference not set to an instance" comes.. Pin
Samiullah4-Aug-08 22:17
Samiullah4-Aug-08 22:17 
GeneralRe: Why the error message like "Object reference not set to an instance" comes.. Pin
Vimalsoft(Pty) Ltd4-Aug-08 22:56
professionalVimalsoft(Pty) Ltd4-Aug-08 22:56 
hi

Well there are couple of things that you are not doing right in your code. Your comments are interfering with your code. Your code is creaming "Put me inside a Function"

You have used unnecessary things in your code. if you can try to write your code like this

        public SqlDataReader GetData()
        {
            SqlDataReader rd;
            SqlConnection con;
            SqlCommand cmd = new SqlCommand();

            string ConnectionString = "server=INDUS-SERVER;uid=sa;pwd=victory;database=northwind";

            con = new SqlConnection(ConnectionString);

            cmd.CommandText = "SELECT FirstName, LastName" + "FROM Employees" + "WHERE (LastName LIKE @Find)";

            cmd.Connection = con;

            cmd.Parameters.Add(new SqlParameter("@Find", SqlDbType.NVarChar, 20, "LastName"));

            cmd.Parameters["@Find"].Value = txtFind.Text;

            try
            {
                con.Open();

                // Execute the query
                rd = cmd.ExecuteReader();
                rd.Close();

                con.Close();
            }
            catch (SqlException e)
            {
                Messagebox.show(e.Message);
            }
            return rd;
        }
    }
}



Now things are Better, because Previously you just opened the Connection where you were not supposed to, remember that you have to connect to the Database when you want to execute something. after you are done you close it, and now this function returns a reader, then you can iterate through your records or your can just choose to send the data into the datatable and bind the control.

Vuyiswa Maseko,

Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding

VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za


GeneralRe: Why the error message like "Object reference not set to an instance" comes.. Pin
Samiullah5-Aug-08 1:14
Samiullah5-Aug-08 1:14 
GeneralRe: Why the error message like "Object reference not set to an instance" comes.. Pin
AtulRane5-Aug-08 1:23
AtulRane5-Aug-08 1:23 
Questionuser interacting windows forms Pin
prasadbuddhika4-Aug-08 21:30
prasadbuddhika4-Aug-08 21:30 
AnswerRe: user interacting windows forms Pin
Syed Shahid Hussain4-Aug-08 22:49
Syed Shahid Hussain4-Aug-08 22:49 
GeneralRe: user interacting windows forms Pin
prasadbuddhika6-Aug-08 21:56
prasadbuddhika6-Aug-08 21:56 
QuestionResizing TextBox while resizing window Pin
Admin8874-Aug-08 21:16
Admin8874-Aug-08 21:16 
AnswerRe: Resizing TextBox while resizing window Pin
N a v a n e e t h4-Aug-08 21:35
N a v a n e e t h4-Aug-08 21:35 
QuestionOracle 7.3.4 Pin
kodali ranganadh4-Aug-08 21:16
kodali ranganadh4-Aug-08 21:16 
Questionautomatic updates Pin
laziale4-Aug-08 21:05
laziale4-Aug-08 21:05 
AnswerRe: automatic updates Pin
selcuks4-Aug-08 21:16
selcuks4-Aug-08 21:16 
Questionabout regex: I couldn't understand why it takes 2-10 minutes? [modified] Pin
enginço4-Aug-08 20:33
enginço4-Aug-08 20:33 
AnswerRe: about regex: I couldn't understand why it takes 2-10 minutes? Pin
PIEBALDconsult5-Aug-08 8:14
mvePIEBALDconsult5-Aug-08 8:14 
GeneralRe: about regex: I couldn't understand why it takes 2-10 minutes? [modified] Pin
enginço5-Aug-08 21:26
enginço5-Aug-08 21:26 
GeneralRe: about regex: I couldn't understand why it takes 2-10 minutes? [modified] Pin
enginço5-Aug-08 23:47
enginço5-Aug-08 23:47 
QuestionGet Row ID in KeyPress event [modified] Pin
M Riaz Bashir4-Aug-08 20:23
M Riaz Bashir4-Aug-08 20:23 
AnswerRe: Get Row ID in KeyPress event Pin
cocoonwls4-Aug-08 22:13
cocoonwls4-Aug-08 22:13 
QuestionWpf or GDI Pin
Mogaambo4-Aug-08 19:46
Mogaambo4-Aug-08 19:46 

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.