Click here to Skip to main content
15,887,336 members
Home / Discussions / Database
   

Database

 
GeneralRe: how to add int Value Pin
Mycroft Holmes29-Oct-09 0:11
professionalMycroft Holmes29-Oct-09 0:11 
QuestionMSSQL SERVER Pin
MsmVc28-Oct-09 1:23
MsmVc28-Oct-09 1:23 
AnswerRe: MSSQL SERVER Pin
dan!sh 28-Oct-09 2:24
professional dan!sh 28-Oct-09 2:24 
GeneralRe: MSSQL SERVER Pin
MsmVc28-Oct-09 2:27
MsmVc28-Oct-09 2:27 
GeneralRe: MSSQL SERVER Pin
MsmVc28-Oct-09 18:32
MsmVc28-Oct-09 18:32 
GeneralRe: MSSQL SERVER Pin
Rob Graham29-Oct-09 8:08
Rob Graham29-Oct-09 8:08 
QuestionExecute Nonquery : Connection properly has not been initialized Pin
Mangesh Tomar27-Oct-09 22:56
Mangesh Tomar27-Oct-09 22:56 
AnswerRe: Execute Nonquery : Connection properly has not been initialized Pin
Covean27-Oct-09 23:24
Covean27-Oct-09 23:24 
I would say just change the order of these two lines from:

cmd = new OleDbCommand(query, con);
con = new OleDbConnection(this.connectionString);

to:

con = new OleDbConnection(this.connectionString);
cmd = new OleDbCommand(query, con);

because you initializing your OleDbCommand (cmd) with a not initilized connection value.


Edit:
I reviewed your code and saw some other things you do wrong.
Your function btnAdd_Click should look like:

private void btnAdd_Click(object sender, EventArgs e)
{
    int rows;
    query = "INSERT INTO master(RegNo,Name)VALUES(@RegNo,@Name)";
    con = null;

    try
    {
        con = new OleDbConnection(this.connectionString); 
        con.Open();

        cmd = new OleDbCommand(query, con);
        cmd.Parameters.AddWithValue("@RegNo", txtRegNo.Text );
        cmd.Parameters.AddWithValue("@Name", txtName.Text );

        rows = cmd.ExecuteNonQuery();
        if (rows > 0)
            MessageBox.Show("records inserted successfully");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        if(con != null)
            con.Close();
    }
}

Greetings
Covean

PS: Its a not the best way to do queries in the ui-code.
AnswerRe: Execute Nonquery : Connection properly has not been initialized Pin
i.j.russell27-Oct-09 23:25
i.j.russell27-Oct-09 23:25 
AnswerRepost Pin
Not Active28-Oct-09 1:12
mentorNot Active28-Oct-09 1:12 
QuestionSSIS Permission Problem Pin
Vimalsoft(Pty) Ltd27-Oct-09 22:05
professionalVimalsoft(Pty) Ltd27-Oct-09 22:05 
AnswerRe: SSIS Permission Problem Pin
Rob Graham29-Oct-09 8:39
Rob Graham29-Oct-09 8:39 
GeneralRe: SSIS Permission Problem Pin
Vimalsoft(Pty) Ltd29-Oct-09 20:17
professionalVimalsoft(Pty) Ltd29-Oct-09 20:17 
QuestionEnumAvailableSqlServers does not list SQL 2000 server. Pin
hoangthu197427-Oct-09 21:15
hoangthu197427-Oct-09 21:15 
AnswerRe: EnumAvailableSqlServers does not list SQL 2000 server. Pin
Abhishek Sur27-Oct-09 22:46
professionalAbhishek Sur27-Oct-09 22:46 
GeneralRe: EnumAvailableSqlServers does not list SQL 2000 server. Pin
hoangthu197427-Oct-09 22:49
hoangthu197427-Oct-09 22:49 
GeneralRe: EnumAvailableSqlServers does not list SQL 2000 server. Pin
Abhishek Sur27-Oct-09 22:53
professionalAbhishek Sur27-Oct-09 22:53 
GeneralRe: EnumAvailableSqlServers does not list SQL 2000 server. Pin
hoangthu197427-Oct-09 23:01
hoangthu197427-Oct-09 23:01 
Questionhow to desinged tables? Pin
iceman861627-Oct-09 15:55
iceman861627-Oct-09 15:55 
AnswerRe: how to desinged tables? Pin
Mycroft Holmes27-Oct-09 20:57
professionalMycroft Holmes27-Oct-09 20:57 
GeneralRe: how to desinged tables? Pin
iceman861627-Oct-09 22:43
iceman861627-Oct-09 22:43 
GeneralRe: how to desinged tables? Pin
Mycroft Holmes28-Oct-09 14:32
professionalMycroft Holmes28-Oct-09 14:32 
GeneralRe: how to desinged tables? Pin
iceman861628-Oct-09 15:17
iceman861628-Oct-09 15:17 
GeneralRe: how to desinged tables? Pin
Mycroft Holmes28-Oct-09 15:23
professionalMycroft Holmes28-Oct-09 15:23 
Questionobject reference not set to an instsnce of an object Pin
Mangesh Tomar27-Oct-09 9:34
Mangesh Tomar27-Oct-09 9:34 

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.