Solved

working con binding combobox

Posted on 2010-08-26
8
322 Views
Last Modified: 2012-05-10
I'm a beginner C# programmer, I want to read in a text box a 'PartNo' that PartNo, i'm gonna look it for in a database and if it exists, bring information to a label (per example, description of this partno), and if it not exists, bring a  message box saying, "PartNo Not found",
How can i do this ? one idea, is by code.  make a sql connection, then with the command such SELECT * FROM Inventory bring data, to where ? a data adapter or something ?
then, how i can access to it ? then something like lbldescription.text= database.column.value or something, this is what i need to know, knowing how it works, practicing y i can so much things,
i appreciate your help
0
Comment
Question by:TSTechNA
  • 4
  • 4
8 Comments
 
LVL 7

Expert Comment

by:jdavistx
ID: 33533265
If you simply wanting to view the data in your database, then there are much simpler alternatives than creating a C# app.

One such alternative is Crystal Reports.  You can use Crystal to create simple forms that you can format, edit and save the returned data from your database.

If you want to go the C# route, then there are several ways to accomplish your goal. Two of which would be:
- Bind your controls to your database fields.
- Generate the SQL yourself to retrieve the data.

Personally, I would think you'd want to go with the second method so that you can get a better understanding of what's going on in your program.  You have the basic idea.

- Connect to your database
- Query your database to return the data you want.
- Parse the data
- Update your form based on the parsed data.

There's a lot of tutorials out there, but maybe this will get you started?
0
 

Author Comment

by:TSTechNA
ID: 33533722
jdavistx,

In another moment i would like to explain me better the option of Crystal Reports, so, i can be able to present reports to my managers.

In this case, the application i'm working on, is for inventory, input, and output,
case input: i want to get from a textbox the partno, so i can search the part in my database, if it exists then ask in another textbox how many articles from this partno i'm gonna add to my stock

As you say, that's what i need to learn, working with data from database.
I can connect to the database, then where this data is, how i can manipulate, then how i update the database after validating and computing.

0
 
LVL 7

Accepted Solution

by:
jdavistx earned 500 total points
ID: 33533835
Well, you can't use Crystal Reports to insert data in to your database.  You could embed a Crystal Report in to your C# app, but let's not worry about that.

There's no shortage of tutorials for C# database applications:
http://www.csharphelp.com/2007/04/designing-a-winform-in-c-and-linking-it-to-a-sql-server-database/
http://www.dreamincode.net/forums/topic/31314-sql-basics-in-c%23/
http://www.codeproject.com/KB/database/sql_in_csharp.aspx

I think there's even some pretty detailed ones available on MSDN, but I can't seem to find them at the moment.

Any of the above, I would think, would be able to get you started with a simple C#/SQL app.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:TSTechNA
ID: 33546934
The first link helped a lot, I made a test, and i inserted data into the database.
Now, getting back,
How i bring data from a table of a database onto my variables in C#?
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 33557971
Well, I suppose a very simple example would be something like:




try
{
	using( var sqlConn = new SqlConnection(connectionString) )
	{
		sqlConn.Open();
		
		string s;
		var cmd = new SqlCommand("SELECT column FROM table", sqlConn);
		s = (string)cmd.ExecuteScalar();
		MessageBox.Show(s);
	}
}
catch(Exception e){ MessageBox.Show("There was an error when trying to retrieve the data!\n\nThe error is as follows:\n" + e.ToString(), "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Error);	}

Open in new window

0
 

Author Comment

by:TSTechNA
ID: 33563390
I'll try that code tonight and i'll let you know

I made a maintenance form, where i can modify the database from a DataGridView, and it was easy, cause i did it all in design mode, just configuring the dataset with a wizard and dragging the table to the form.

But when, i click the save(update) button in the top bar, i get the next error

Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

Do i need to modify some part of the code? o how i can solve this? this tool was very helpful to feed inventory data.
Or I need to make a form and make a command with the Update ?

This error i get, when i'll do the same locally in my laptop, everything's good, no error.

At my laptop i'm using SQL Server 2008, sa user, then, with a network with servers, i'm using SQL Server 2005 with sa user also
 
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 33581795
If I remember right, you should use a SqlCommandBuilder to generate those commands before you call Update on your SqlDataAdapter.
0
 

Author Closing Comment

by:TSTechNA
ID: 33611844
Great!, With these tutorials and the fast answer to my questions i finally made what i want.
There's a lot more to learn
thanks
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question