Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

20 replies to this topic
#1
Posted 25 June 2012 - 05:12 PM
I want to create a form. For example, i have a rectangle with length 3m and breadth 2m. To find the area of the rectangle is length * breadth.
To solve this pblm, how to do I use database in microsoft visual studio 2010; what are the codings?
To solve this pblm, how to do I use database in microsoft visual studio 2010; what are the codings?
#2
Posted 25 June 2012 - 05:25 PM
http://msdn.microsof...y/ms233763.aspx
this is how you can create a db in vs
for how to communicate with database inside C# you must look inside topic that i created here...it's
Null Values In Table After Saving Data
this is how you can create a db in vs
for how to communicate with database inside C# you must look inside topic that i created here...it's
Null Values In Table After Saving Data
Microsoft Student Partner, Microsoft Certified Professional
#3
Posted 25 June 2012 - 06:29 PM
percis, you want to find the area of a rectangle which width/height are given. Why do you need a database to do that?
#4
Posted 25 June 2012 - 06:51 PM
i get the values such as length and breadth from the database.percis, you want to find the area of a rectangle which width/height are given. Why do you need a database to do that?
#5
Posted 26 June 2012 - 12:47 AM
something similar to
SELECT width, height, (width * height) AS area FROM...
I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.
#6
Posted 26 June 2012 - 04:14 AM
OK ... Let us assume that you have a database named 'Geometry' in SQL server which has a table named 'Rectangles' -- the table has two columns, width & height, of type int. Now our job is to retrieve that table data and show in a data-grid but with an extra column that will show the 'area' of the rectangle. So the steps are...
- Create a SqlConnection object with the connection string for that database and open the connection.
- Create a SqlAdapter object for that connection object and with the SQL query Orjan posted.
- Create a DataTable object and ask the adapter to fill for that SQL query.
- Add an extra column in the DataTable object -- 'Area'.
- In a foreach loop, for each row, calculate the area from the width & height and update the each row of the DataTable object
- Finally assign the DataTable object as a DataSource to the DataGridView.
void DBTest() { try { // Step 1 System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Geometry;Integrated Security=True"); conn.Open(); // Step 2 System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM Rectangles", conn); // Step 3 System.Data.DataTable table = new System.Data.DataTable(); adapter.Fill(table); // Step 4 table.Columns.Add("Area"); // Step 5 foreach (System.Data.DataRow row in table.Rows) { object[] cells = row.ItemArray; cells[2] = Convert.ToInt32(cells[0]) * Convert.ToInt32(cells[1]); row.ItemArray = cells; } // Step 6 dataGridView1.DataSource = table; } catch (Exception exc) { Console.WriteLine("Error: " + exc.Message); } }
#7
Posted 26 June 2012 - 05:20 AM
my query does the calculation and adds the field area, kernelcoder, so that part shouldn't be needed in your code.
I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.
#8
Posted 26 June 2012 - 05:21 AM
Agreed. So foreach loop can be removed.my query does the calculation and adds the field area, kernelcoder, so that part shouldn't be needed in your code.
#9
Posted 26 June 2012 - 07:56 PM
OK ... Let us assume that you have a database named 'Geometry' in SQL server which has a table named 'Rectangles' -- the table has two columns, width & height, of type int. Now our job is to retrieve that table data and show in a data-grid but with an extra column that will show the 'area' of the rectangle. So the steps are...
And here is the code for the steps...
- Create a SqlConnection object with the connection string for that database and open the connection.
- Create a SqlAdapter object for that connection object and with the SQL query Orjan posted.
- Create a DataTable object and ask the adapter to fill for that SQL query.
- Add an extra column in the DataTable object -- 'Area'.
- In a foreach loop, for each row, calculate the area from the width & height and update the each row of the DataTable object
- Finally assign the DataTable object as a DataSource to the DataGridView.
void DBTest() { try { // Step 1 System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Geometry;Integrated Security=True"); conn.Open(); // Step 2 System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM Rectangles", conn); // Step 3 System.Data.DataTable table = new System.Data.DataTable(); adapter.Fill(table); // Step 4 table.Columns.Add("Area"); // Step 5 foreach (System.Data.DataRow row in table.Rows) { object[] cells = row.ItemArray; cells[2] = Convert.ToInt32(cells[0]) * Convert.ToInt32(cells[1]); row.ItemArray = cells; } // Step 6 dataGridView1.DataSource = table; } catch (Exception exc) { Console.WriteLine("Error: " + exc.Message); } }
thaks a lot for the solution. I'm lost along the way. Is it possible to from step1 as where should i click in print screen and where should i enter the coding? Please....Im anxiously waiting for ur reply.
#10
Posted 26 June 2012 - 08:36 PM
If you just want to execute the code successfully, you can call the DBTest method from your form's Load event handler. But note that you have a have a sql database and you have to change the connection string accordingly.
#11
Posted 27 June 2012 - 12:12 AM
If you just want to execute the code successfully, you can call the DBTest method from your form's Load event handler. But note that you have a have a sql database and you have to change the connection string accordingly.
I'm lost. i really need help in setting up sql database/ any step from the beginning. Im using microsoft visual 2010. could u help me?
#12
Posted 27 June 2012 - 12:47 AM
First you need to install, Microsoft SQL Server. Is it there installed on your machine? Note that, you also need to install SQL Management Studio. If yes, the rest is easy to create a database and table -- read this tutorial about it.
However, we can use Microsoft Access Database to store the height and width for rectangles. If you want to use MS-Access, we need to change the code a bit. Let us know which one you have successfully installed on your machine.
However, we can use Microsoft Access Database to store the height and width for rectangles. If you want to use MS-Access, we need to change the code a bit. Let us know which one you have successfully installed on your machine.
Also tagged with one or more of these keywords: database
Language Forums →
Databases →
SOLVED: Conditional insertion of rows via MySQLStarted by PuddingEatsPanda, 19 Mar 2016 ![]() |
|
![]() |
||
General Forums →
General Programming →
sql database 2008Started by rhysgardner, 31 Jan 2016 ![]() |
|
![]() |
||
General Forums →
General Computing →
What are some free database servers for testing cross platform application?Started by BlueBox, 03 Jan 2016 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
ASP, ASP.NET and Coldfusion →
Problem at insert and delete, and a database call questionStarted by FrancoPapalardo, 13 Dec 2015 ![]() |
|
![]() |
||
General Forums →
Mobile Development →
How to add a database inside an Android applicationStarted by jasonalien, 18 Aug 2015 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download