What concepts should I study to accomplish this?
I am such a newbie to c# I have to ask questions before I can get started!
What I want to do is enter a numeric number into a text box, send it to an attached sql compact database, che开发者_如何学Gock to see if the number is in the table, if true return the data to the form. If false, I want to run some code that will get the information and update the table, add to table, send to the form. Other then creating sql tables via C#, Could someone help me prototype this concept so to speak so I can start reading up on the concepts so that I can start building this portion of my project? Thanks.
There are many different ways to do what you are describing. A quick and easy way to handle this scenario would be to use WPF for the user interface and LINQ to SQL for the database access. There are tons of tutorials on both technologies, but here are the basic steps:
Step 1: Create a new WPF project in Visual Studio
Step 2: Add a LINQ to SQL class and map it to your Database
Step 3: Edit the MainWindow.xaml and add the input textbox, check button, and results textbox
Sample code for MainWindow.xaml (note this is quick and dirty):
<Window x:Class="WPFPlayground.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Horizontal" Height="30">
<TextBox Name="InputTextBox" Width="50"/>
<Button Name="CheckButton" Content="Check DB" Click="CheckButton_Click"/>
<TextBox Name="ResultsTextBox" Width="100"/>
</StackPanel>
</Grid>
</Window>
Step 4: Edit the code behind of MainWindow.xaml.cs to handle the button click event
Sample code for Click event in MainWindow.xaml.cs (again quick and dirty)
private void CheckButton_Click(object sender, RoutedEventArgs e)
{
// Get instance of my LINQ to SQL datacontext
var db = new MyDbDataContext();
// Try to get the record that matches the text in the InputTextBox
var data = db.TableName.FirstOrDefault(r => r.Id == InputTextBox.Text);
// Was able to find a matching record so show results data
if (data != null)
{
ResultsTextBox.Text = data.EventDesc;
}
else
{
// do what ever you need to do when there is no match
}
}
Step 5: Learn some best practices and do not use this sample code :)
Have fun.
I'd head over to the MS Development for Beginners site, which will help you get started with the fundamentals as well as lead you on to greater heights.
The Tier 1 lessons will take you through Visual Studio Express, and get you writing a simple application.
The Tier 2 lessons introduce some of the core concepts underlying Windows development, including reading and populating forms.
The Tier 3 lessons then introduce some of the concepts around connecting to Databases, including updating them.
The Aspiring Professional section then points you in the direction of further resources including lots of training materials.
Have fun!
I would work on basic SQL CRUD operations and ADO.NET (particularly the SqlClient namespace). Those are the most important concepts for what you're describing, and the ones that will take the most depth of understanding.
The important concepts here are going to be CRUD operations, event based development, and just the .NET framework in general. You can do all of these things in Visual Studio 2010 C# Express Edition (free), and there are many tutorials around on the net. Need anything more specific?
精彩评论