WabiSabi's Profile User Rating: -----

Reputation: 51 Whiz
Group:
Active Members
Active Posts:
201 (0.14 per day)
Joined:
31-December 10
Profile Views:
5,141
Last Active:
User is offline Private
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   WabiSabi I would rather ask a dumb question and look stupid once than to remain ignorant forever.

Posts I've Made

  1. In Topic: connecting to ms sql server 2008 using oledb

    Posted 29 Nov 2012

    C# is a little different so the syntax is different. When the error is something like "did you mean to invoke the method?" then you should call a method. For example cmd.ExecuteReader; should be cmd.ExecuteReader(); This now shows no errors for me but I didn't test it.
            public bool validateuser(string password, string username)
            {
                OleDbCommand cmd = new OleDbCommand();
               // DbConnection db;
                //cmd.Connection = db.connection;
                cmd.CommandText = "select * from userlogin where password = ? and username = ?";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("", password);
                cmd.Parameters.AddWithValue("", username);
    
                bool found = false;
                OleDbDataReader dr = default(OleDbDataReader);
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    found = true;
                }
    
                return found;
            }
    


    The following works. I have tested it. I think you need to put whatever provider you actually use, though. Maybe you can get yours working by looking at this example. Good luck!

                con = new System.Data.OleDb.OleDbConnection();
                con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/ACTUAL_FILEPATH_GOES_HERE.accdb;Jet OLEDB:Database Password=MyDbPassword;";
                con.Open();
    
                string comment = "Insert!";
                int id = 1; //this is related in the other table...  must be an ID from the other table; primary key, maybe? Or just a key...
    
                OleDbCommand Cmd = new OleDbCommand("Insert Into Comments([Comment], ContactID) Values (@CommentParam, @ContactIDParam)", con);
    
                Cmd.Parameters.AddWithValue("@CommentParam", comment);
                Cmd.Parameters.AddWithValue("@ContactIDParam", id);
    
                Cmd.ExecuteNonQuery(); 
    
                //OR you can do it this way:
                OleDbCommand cmd = new OleDbCommand();
    
                cmd.Connection = con;
                cmd.CommandText = "INSERT INTO Comments([Comment],[ContactID])  VALUES (@Comment, @ID)";
                cmd.Parameters.Add("@Comment", OleDbType.VarChar).Value = "HELPME";
                cmd.Parameters.Add("@ID", OleDbType.Integer).Value = 2;
    
                cmd.ExecuteNonQuery(); 
    
                con.Close();
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
6

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

WabiSabi has no profile comments yet. Why not say hello?