CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Join Date
    Feb 2010
    Posts
    25

    Smile Questions regarding C#

    Hello!

    I have several questions regarding C# language. I am a begginer programmer and I am working on a project. here are my questions:
    1. I am using VS C# 2008. I want to use a local DB with my program (a file that will sotre information). I am thinking about using the SQL CE server, uncluded with the VS. I use local database user control from visual studio and create a DB file, but how can I connect to it (a sample script would be nice).
    2. Using panels - how can I make multiple panels on one form - on button click I change the things in the form (ets say textbox), without changing the form.
    3. How can I make an dynamic menu/app from the DB - Lets say I have 2 columns in the DB - Name and Information - WHen i get in a form (Form1), I get an dynamic menu with all the things under Names in the DB and when I click on a name it will open new panel/form, displaying the information for the name (Column Information).
    4. Drawing things in C#. Any tutorials, samples, programs are welcome! More specially simetry drawing - point symetry, lines, figures.


    I will be really glad If u can answer any of the things. Will really appreciate sample scripts, applications and especially tutorials.


    Alex Barakov

  2. #2
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    For no 4. Here are some Links


    http://www.deitel.com/Books/VisualC2...6/Default.aspx

    here download the Code examples into Your computer. There Are tons of useful example Programs Project including drawing and shapes. You just go through all the examples, many of this will surely help you....

    http://msdn.microsoft.com/en-us/magazine/cc721604.aspx

    http://stackoverflow.com/questions/1...rawing-program

    http://social.msdn.microsoft.com/For...7-8fff11b4139c

  3. #3
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    Thanks, will look at this links right away!

    Looking forward to getting more links/tuts/samples on all of the questions above.

  4. #4
    Join Date
    Dec 2009
    Posts
    22

    Re: Questions regarding C#

    To create the local DB:
    In the menu bar click View->Server Explorer.
    In the Server Explorer right click Data Connections and click add connection
    Select Microsoft SQL Server Database File
    Give the DB a name, a save it to you harddrive.

    To create tables in the database file:
    click the plus on the newly created database connection
    right click tables and select Add New Table
    input the table structure

    To add the database to the project:
    In the Solution Explorer right click your project and select Add->New Item
    Select LINQ to SQL Classes, name it and click Add
    Double click the newly created item in the Solution Explorer
    Now drag the table from the Server Explorer into the middle of VS (the white space that is now there)
    You will be asked if you would like to add the Database Connection to the project, select Yes.
    Now you sould see a model of you table.
    Save the .dbml file

    To interact with the database:
    create a new database object:
    Code:
    var db = new dbDataContext(); // if your .dbml file is called db
    var db = new databaseDataContext(); // if your .dbml file is called database
    Now you can access the data in the database using LINQ to SQL
    e.g.:
    Code:
    var row = db.SomeTable.Where(a => a.id == 4); // SELECT * FROM SomeTable WHERE 'id' = '4';

  5. #5
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    Thank you for the answers. Still looking forward to getting more things!

    About that database. Can you give me an example about:

    A databse nammed testdb
    A table named users
    with columns: ID and User

    Lets say I have winforms application with 2 text boxes and 2 buttons. When I enter the User text in textBox1 and press button1, it will import the data from it into the DB (under ID 1, if and using autoincrease). And when I click button 2, it will show the data where the ID is 1 to textBox2.

    Thanks in advance!

  6. #6
    Join Date
    Dec 2009
    Posts
    22

    Re: Questions regarding C#

    A databse nammed testdb
    A table named users
    with columns: ID and User

    Lets say I have winforms application with 2 text boxes and 2 buttons. When I enter the User text in textBox1 and press button1, it will import the data from it into the DB (under ID 1, if and using autoincrease). And when I click button 2, it will show the data where the ID is 1 to textBox2.
    something like this:
    Code:
    private void button1_Click(object sender, EventArgs e)
    {
        var db = new testdbDataContext();
        db.Users.InsertOnSubmit(new User() { User1 = textBox1.Text }); //ID is auto assigned and incremented
        db.SubmitChanges();
    }
    
    private void button2_Click(object sender, EventArgs e)
    {
        var db = new testdbDataContext();
        var user = db.Users.Single(a => a.ID == 1); // get the user with ID = 1
        textBox2.Text = user.User1;
    }
    The autogenerated names of the columns in the table might differ from the names that you have given the columns in the database.
    In this case it is because the table and the column shares the same name.
    It would make more sense to call the column 'username' or something like that.

  7. #7
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    I am working with databse: databse
    table: Users
    Columns: ID (primary key, auto increase), Username and Password
    I am using the following code:

    var db = new databaseDataContext();

    db.Users.InsertOnSubmit(new User() { Username = textBox1.Text }); //ID is auto assigned and incremented
    db.SubmitChanges();


    It is not inserting any values in the DB, but I can't understand waht is this doing:


    db.Users.InsertOnSubmit(new User() { Username = textBox1.Text });

    especially the thing "new User()", as I don't have anything ithe DB called 'User' and IF i change it to anything else i get errors... I will be glad If you can tell me why it is not working and what does that row mean.


    Thanks for the answers.

    PS. Maybe we can talk over on msn/skype, in case I have mroe answers and you don't mind answering them..

  8. #8
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    I am working on similar project too, so was also a great help for me too....but now my problem is little diffrent.....
    in table users I have 2 columns called username and password...I have already Inserted a value for each columns....I dont have any Intention to adding further data to it for now....I now want to store these values of Username and password from the database and store it in the string variavles (say s1 and s2)......Please Help me here
    Last edited by rocky_upadhaya; February 11th, 2010 at 09:40 PM.

  9. #9
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    I have successfully got that value and stored it in string....like in
    Code:
                var usrnm = db.usrInfo_tables.FirstOrDefault();
                string uname = usrnm.Username.ToString();
                MessageBox.Show(uname);
    But after this I changed the value of username from table from server explorer but the message box showed the earlier value....what should I do to change the value in database and in the program too??

  10. #10
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    I have noticed an delay on this. The program just doesen't seem to show the right that right away, you need to turn it off, refress the DB, wait a couple of seconds and than turn it on again. Don't know why's that and I honestly don't care.

    Sorry for beeing rude, but this is my topyc and I don't like it beeing spammed!

  11. #11
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    What?? you mean you dont like me getting involved in your thread??
    Last edited by rocky_upadhaya; February 12th, 2010 at 02:18 AM.

  12. #12
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    Um, why don't you make ur own thread for asking questions??

  13. #13
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    You are going all wrong here! Since I was working on almost same project here i thought it would be better if I would also participate in this discussion coz it would help both of us...BTW this is an public discussion forum where we all share the knowledge we have with others....Some people here are highly qualified professionals who spend their valuable time helping the one who want to learn like you and me.....Remember they are not your personal tutors.....I have not messed up your problems or taken your topic to another path....I just continued your thread coz I thought our problem was similar............anyway I will not continue this thread from now....Take care! and stop treating this forum as your personal Homepage

  14. #14
    Join Date
    Feb 2010
    Posts
    25

    Re: Questions regarding C#

    Quote Originally Posted by rocky_upadhaya View Post
    You are going all wrong here! Since I was working on almost same project here i thought it would be better if I would also participate in this discussion coz it would help both of us...BTW this is an public discussion forum where we all share the knowledge we have with others....Some people here are highly qualified professionals who spend their valuable time helping the one who want to learn like you and me.....Remember they are not your personal tutors.....I have not messed up your problems or taken your topic to another path....I just continued your thread coz I thought our problem was similar............anyway I will not continue this thread from now....Take care! and stop treating this forum as your personal Homepage
    I am sorry about this, but I don't think our problems were similar. Anyway you are right about the forums - this is a community, but the things you have written help me in no way.

    Thanks anyway if you thought you can help.

  15. #15
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Questions regarding C#

    No! I have implemented all the suggestion of jonlist and my project is similar to your's have a look at my thread "starting Datatbase" http://www.codeguru.com/forum/showthread.php?t=492538 the difference is how we implement it....wish I could help you but like new I am also new to this language and this is my first database application download and evaluate mine project....

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured