Results 1 to 7 of 7

Thread: Help Creating and Modfying Data Base in C# Visual Studio 2010

  1. #1
    Join Date
    May 2010
    Posts
    3,815
    Rep Power
    0

    Post Help Creating and Modfying Data Base in C# Visual Studio 2010

    Hey guys I am creating an inventory program in C# and I need to store the data and be able to add/delete/update the database. How do I go about doing this? I am using Visual Studio 2010
    CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP-> IF THE TRUTH HURTS CLOSE THE THREAD
    If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU !

  2. #2
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    Are you using SQL server 2008 r2 or MYSQL C# Connector..

    Personally I like using MYSQL C# connector because its light weight and faster than SQL server 2008..

    Download connector from here
    http://www.mysql.com/downloads/connector/net/


    Ohhh and its free BTW.

    CRUD on MYSQL connector latest version
    string connectionString ="server=localhost;user=root;database=YourDataBase ;port=3306;password=;";//connection string
    MySqlConnection conn = new MySqlConnection();//MYSQL connection function



    Insert/Add
    conn = new MySqlConnection(connectionString);//passing connection string into the connection function
    conn.Open();
    MySqlCommand cmd = conn.CreateCommand();//create a command function that utilises the connection string to execute commands
    cmd.CommandText = "INSERT INTO yourTable VALUES (@fname,@lname)";//insert firstname and lastname into your table
    cmd.Prepare();

    //---------------
    cmd.Parameters["@fname"].Value = firstname.Text;//example the string is passed from textbox
    cmd.Parameters["@lname"].Value = lastname.Text;//example the string is passed from textbox
    //---------------
    cmd.ExecuteNonQuery();//Command is executed. hence its written to database
    conn.Close();//close connection
    Update
    conn = new MySqlConnection(connectionString);
    conn.Open();
    cmd = conn.CreateCommand();
    cmd.CommandText = "UPDATE yourTable set price=@NewPrice WHERE Console =@conSoleName";
    cmd.Prepare();
    cmd.Parameters["@NewPrice"].Value = "25000";
    cmd.Parameters["@conSoleName"].Value = "PSP";
    cmd.ExecuteNonQuery();
    conn.Close();

    Delete
    conn = new MySqlConnection(connectionString);
    conn.Open();
    cmd = conn.CreateCommand();
    cmd.CommandText = "Delete * from yourTable";
    cmd.Prepare();
    cmd.ExecuteNonQuery();
    conn.Close();

    Here is the documentation it will help you out alot..... http://dev.mysql.com/doc/refman/5.5/...ector-net.html
    That's the latest...

    ------------------------------------------------------
    Here are some example.. but they are using the older 1.0 version. Its basically the same. But here anyway
    http://bitdaddys.com/MySQL-ConnectorNet.html
    Last edited by mobile_fan_2k5; Nov 17, 2011 at 11:36 PM.
    Pc= Hp dv6t

  3. #3
    Join Date
    May 2010
    Posts
    3,815
    Rep Power
    0

    Default

    Thanks will look into it right now. I was thinking about using and linking an Access Database file but this seems a lot easier.
    CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP-> IF THE TRUTH HURTS CLOSE THE THREAD
    If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU !

  4. #4
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    its not just easier its more practical..You can build scalable apps with it. Its not as powerful as SQL server 2008 r2 but it beats it in terms of speed.
    Pc= Hp dv6t

  5. #5
    Join Date
    May 2010
    Posts
    3,815
    Rep Power
    0

    Default

    Thanks, I am reading into it now...

    This is what I am planning to do... I am creating an Inventory program for three departments. For each I am recording the following devices Computer, Keyboard, Mouse, Printers with the following details Device Name, Serial and Quantity and technician who added or removed the device. All from within a GUI. so trying to get my bearings on this all..
    CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP-> IF THE TRUTH HURTS CLOSE THE THREAD
    If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU !

  6. #6
    Join Date
    Jul 2007
    Posts
    16,974
    Rep Power
    27

    Default

    I know how to do this with a cookie. learning how to do with database as we speak.
    SLAPPA Phenom II AM3 Overclocking Essentials
    I HAVE HIGHEST OC ON TECHJA 4.2ghz
    4890oc beats gtx 285
    PS3 FAILCAKE
    ps3 only advantage is bluray
    4890 oc roundup
    http://miniprofile.xfire.com/bg/sh/type/0/skugpezz.png
    Mi know dem fear mi!!!!! Gigabyte 790x ud4p
    phenom 2 955@3.8ghz 24/7 stable , 4GB ddr3 1333@1.5ghz ,3850 256MB (temp card) (4890 soon),700 watt dual rail psu, (overclocking rules) my avatar represents my personality

  7. #7
    Join Date
    May 2010
    Posts
    3,815
    Rep Power
    0

    Default

    Quote Originally Posted by pezz View Post
    I know how to do this with a cookie. learning how to do with database as we speak.
    Cool, I will be doing my database course for my IT BS next semester... should be interesting... lol...

    mind giving me some tips and help with this lil project tho?
    CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP-> IF THE TRUTH HURTS CLOSE THE THREAD
    If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •