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
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
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
Updatestring 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
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
Thanks will look into it right now. I was thinking about using and linking an Access Database file but this seems a lot easier.
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
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..
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