Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. converting console base application to windows form

converting console base application to windows form

Scheduled Pinned Locked Moved Database
csharpdatabasevisual-studiolinqgraphics
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    qureshiaquib wrote:

    need some help

    With what, exactly? Add a reference to System.Windows.Forms, add a Form, run it in the main-method. And please, do use parameterized queries[^]. Without it, the entire idea of "security" becomes a bit useless. Google for "Little Bobby Tables" if you want to know why.

    Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

    S Offline
    S Offline
    shaikh adil
    wrote on last edited by
    #3

    with what exactly means? i just want to build a form which checks the user id and a password from the database which is already present. a simple login windows form which redirect to another form if the password is correct or if the password is not correct then redirects to the same login form. a simple of two text boxes and a submit button. but the code..what to do with that? mine is of console based. how to do it in windows form i am a student.learning programming in university can u help me out

    P L 2 Replies Last reply
    0
    • S shaikh adil

      with what exactly means? i just want to build a form which checks the user id and a password from the database which is already present. a simple login windows form which redirect to another form if the password is correct or if the password is not correct then redirects to the same login form. a simple of two text boxes and a submit button. but the code..what to do with that? mine is of console based. how to do it in windows form i am a student.learning programming in university can u help me out

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #4

      As Eddy has mentioned, build a form with the text boxes, and reuse the appropriate code you have in the console app in the windows form app. I understand you are learning right now, and the following is dangerous as it allows for SQL injection attacks:

      SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection);

      You do not want to use string concatenation for building a query, but use parameterized queries instead. Take a look at SQL Injection Attacks and Some Tips on How to Prevent Them[^] to learn how to prevent them.

      "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

      S 1 Reply Last reply
      0
      • P Paul Conrad

        As Eddy has mentioned, build a form with the text boxes, and reuse the appropriate code you have in the console app in the windows form app. I understand you are learning right now, and the following is dangerous as it allows for SQL injection attacks:

        SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection);

        You do not want to use string concatenation for building a query, but use parameterized queries instead. Take a look at SQL Injection Attacks and Some Tips on How to Prevent Them[^] to learn how to prevent them.

        "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

        S Offline
        S Offline
        shaikh adil
        wrote on last edited by
        #5

        can u have any xample which is readymade. Now i have understand that my code is something wrong.. Can you provide me an xample where i can understand the whole scenario. A form which is used for login

        P 1 Reply Last reply
        0
        • S shaikh adil

          can u have any xample which is readymade. Now i have understand that my code is something wrong.. Can you provide me an xample where i can understand the whole scenario. A form which is used for login

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #6

          qureshiaquib wrote:

          Can you provide me an xample where i can understand the whole scenario

          Nope. I am a college professor and it would be against my principles to just hand over a full-blown example, you would not learn much from it. 1. Design your form with your appropriate labels and text boxes (extra credit if you make the password text box **** out the password as it is typed in ), and a log in button. 2. Recycle/reuse your database connection code in which you can run the query after clicking the log in button. 3. If things don't work out well the first time, experiment around with it and use some creativity. You can do it :-D Also, you do not want to store passwords for the user in plain text inside the database. You might want to study up on cryptographic hash functions as well. I am leaving this for you to research and enrich your learning with.

          "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

          S 1 Reply Last reply
          0
          • S shaikh adil

            hey members i need some help. i have made this console base app which connects to a database and retrieves the data from two column. same it is like a login check form. but can i convert this into a windows form application which consist of two text boxes and a login button need some help thanks in advance using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; namespace c_database { class program { static void main(string[] aqu) { string connectionstring =@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\aquib\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True;User Instance=True"; SqlConnection connection= new SqlConnection(connectionstring); try { connection.Open(); Console.WriteLine("connection open"); Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e); Console.Read(); } Console.Write("username>"); string username =Console.ReadLine(); Console.Write("Password>"); string password =Console.Read(); SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection); SqlDataReader reader = null; reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine("welcome" + reader["username"].ToString()); Console.Read(); } Console.WriteLine("user" +username + "does Not exist" ); goto } } }

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #7

            As mentioned -- definitely never concatenate your SQL statements -- use parameters. Here's a link to another excellent article here that bears on your situation: Password Storage: How to do it.[^] I'll also mention that you should use a layered approach: User Interface Layer -- You have the console app, you can write a WinForms app that uses the same layers beneath here. Business Logic Layer -- encapsulates the logic of validating the login details (and other things) (SQL goes here). Data Access Layer -- encapsulates the details of connecting to and interacting with the database. Try it, learn it, live it -- you'll be way ahead of your classmates, and you'll become a chick magnet :cool: .

            P 1 Reply Last reply
            0
            • S shaikh adil

              with what exactly means? i just want to build a form which checks the user id and a password from the database which is already present. a simple login windows form which redirect to another form if the password is correct or if the password is not correct then redirects to the same login form. a simple of two text boxes and a submit button. but the code..what to do with that? mine is of console based. how to do it in windows form i am a student.learning programming in university can u help me out

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              qureshiaquib wrote:

              i am a student.learning programming in university

              ..as I'm reading it, you are doing the learning "here". Welcome to CodeProject University I guess :badger: When is the assignment due? Any chance we could sneak in a short piece (using the CPVanity class) to deny users with a negative reputation access for the first two tries?

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              S 1 Reply Last reply
              0
              • P PIEBALDconsult

                As mentioned -- definitely never concatenate your SQL statements -- use parameters. Here's a link to another excellent article here that bears on your situation: Password Storage: How to do it.[^] I'll also mention that you should use a layered approach: User Interface Layer -- You have the console app, you can write a WinForms app that uses the same layers beneath here. Business Logic Layer -- encapsulates the logic of validating the login details (and other things) (SQL goes here). Data Access Layer -- encapsulates the details of connecting to and interacting with the database. Try it, learn it, live it -- you'll be way ahead of your classmates, and you'll become a chick magnet :cool: .

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #9

                Excellent suggestion on the layers. Griff's article I second as well.

                PIEBALDconsult wrote:

                be way ahead of your classmates, and you'll become a chick magnet

                :laugh: That is signature material right there :-D

                "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

                1 Reply Last reply
                0
                • S shaikh adil

                  hey members i need some help. i have made this console base app which connects to a database and retrieves the data from two column. same it is like a login check form. but can i convert this into a windows form application which consist of two text boxes and a login button need some help thanks in advance using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; namespace c_database { class program { static void main(string[] aqu) { string connectionstring =@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\aquib\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True;User Instance=True"; SqlConnection connection= new SqlConnection(connectionstring); try { connection.Open(); Console.WriteLine("connection open"); Console.WriteLine(""); } catch (Exception e) { Console.WriteLine(e); Console.Read(); } Console.Write("username>"); string username =Console.ReadLine(); Console.Write("Password>"); string password =Console.Read(); SqlCommand command = new SqlCommand("SELECT * FROM [USERS] WHERE Username='" + username + "' AND Password ='" + password + "'" , connection); SqlDataReader reader = null; reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine("welcome" + reader["username"].ToString()); Console.Read(); } Console.WriteLine("user" +username + "does Not exist" ); goto } } }

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  First do Right-Click on Project > References and add the Windows.Forms.dll to the project. then you need to add the namespaces to your class. After that right click on Project and select Properties; From "Application" tab set output type to "Windows Application". Good Luck

                  Meysam

                  1 Reply Last reply
                  0
                  • L Lost User

                    qureshiaquib wrote:

                    i am a student.learning programming in university

                    ..as I'm reading it, you are doing the learning "here". Welcome to CodeProject University I guess :badger: When is the assignment due? Any chance we could sneak in a short piece (using the CPVanity class) to deny users with a negative reputation access for the first two tries?

                    Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                    S Offline
                    S Offline
                    shaikh adil
                    wrote on last edited by
                    #11

                    due is within this week. :| i donno how to do that.

                    L 1 Reply Last reply
                    0
                    • P Paul Conrad

                      qureshiaquib wrote:

                      Can you provide me an xample where i can understand the whole scenario

                      Nope. I am a college professor and it would be against my principles to just hand over a full-blown example, you would not learn much from it. 1. Design your form with your appropriate labels and text boxes (extra credit if you make the password text box **** out the password as it is typed in ), and a log in button. 2. Recycle/reuse your database connection code in which you can run the query after clicking the log in button. 3. If things don't work out well the first time, experiment around with it and use some creativity. You can do it :-D Also, you do not want to store passwords for the user in plain text inside the database. You might want to study up on cryptographic hash functions as well. I am leaving this for you to research and enrich your learning with.

                      "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

                      S Offline
                      S Offline
                      shaikh adil
                      wrote on last edited by
                      #12

                      i can also learn from the project. i can read that and understand. i hae to submit my project but bymistakenly i have mae a console app. plz sir provide me with a readmade form i will understand that whole project. but i cant copy because i have to explain the whole scenario like a presentation so dont bother that i am simply copying and getting my assingment done

                      1 Reply Last reply
                      0
                      • S shaikh adil

                        due is within this week. :| i donno how to do that.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        Read Meysams post, has given you a description of what needs to be done. ..and you should be able to do this within a week, it's not much code. Panicking won't help either, it's more a matter of sitting down, reading the post and Googling a lot :)

                        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                        S 1 Reply Last reply
                        0
                        • L Lost User

                          Read Meysams post, has given you a description of what needs to be done. ..and you should be able to do this within a week, it's not much code. Panicking won't help either, it's more a matter of sitting down, reading the post and Googling a lot :)

                          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                          S Offline
                          S Offline
                          shaikh adil
                          wrote on last edited by
                          #14

                          what is meysam post?

                          L 1 Reply Last reply
                          0
                          • S shaikh adil

                            what is meysam post?

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #15

                            qureshiaquib wrote:

                            what is meysam post?

                            Not a what, but a "whom". I was referring to a good answer to your question that has been sent to you by someone with that name[^]. Did you succeed in adding a reference to the project yet?

                            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups