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. General Programming
  3. .NET (Core and Framework)
  4. c# forms (holy crap i'm not ready for this)

c# forms (holy crap i'm not ready for this)

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpphpdatabasehelp
19 Posts 3 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

    Uranium-235 wrote:

    createDB is topmost enabled and won't let the main form be accessible when it's up.

    You don't need Topmost, just make it a dialog so it automatically disables the calling form:

    CreateDB dbCreator = new CreateDB();
    DialogResult rc = dbCreator.ShowDialog();
    // check rc for success etc.

    Here is a really useful C# tutorial: http://www.charlespetzold.com/dotnet/index.html[^].

    U Offline
    U Offline
    Uranium 235
    wrote on last edited by
    #10

    actually this is throwing me an error. "

    Quote:

    Cannot implicitly convert type 'void' to 'System.Windows.Forms.DialogResult

    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
    
    
        private void Main\_Load(object sender, EventArgs e)
        {
            if(!File.Exists(Directory.GetCurrentDirectory() + "\\\\Tracker.db"))
            {
                this.Enabled = false;
                
                CreateDB dbForm = new CreateDB();
                DialogResult res = dbForm.ShowDialog(); //dbform error
    
                if (res == DialogResult.Cancel)
                    Application.Exit();
            }
        }
    }
    

    public partial class CreateDB : Form
    {
    public event EventHandler CancelPressed;

        public CreateDB()
        {
            InitializeComponent();
                       
        }
    
        private void Cancel\_Click(object sender, EventArgs e)
        {
            if (CancelPressed != null)
                CancelPressed(this, EventArgs.Empty);
        }
    }
    
    L 1 Reply Last reply
    0
    • L Lost User

      You will never learn programming from Google or Youtube. Get yourself a decent book that will teach you properly, starting with the basics. Time spent now will pay dividends in the future.

      U Offline
      U Offline
      Uranium 235
      wrote on last edited by
      #11

      I learned PHP and VB from googling. Actually I learned PHP because a game named Tribes used the zend engine and I picked up a PHP book and realized I knew the syntax better than the book. Did PHP for 10 years and made some pretty impressive stuff. I also did some stuff in VB that was pretty advanced. But I haven't done it in a few years (like, 4?) Once you learn many of the basics of .net, all I have left is translating it into the syntax of c#, which IMO has better structure than VB, and a structure i'm more familiar with (logic and conditions like PHP, some variables like C++, which I took in high school) I don't think I could relearn the VB crap. I'm used to &&, ||, if() foreach loops, all in PHP. One thing I didn't like is you can't do multiple logical comparisons in switch/case, but that it rarely used in PHP

      1 Reply Last reply
      0
      • U Uranium 235

        actually this is throwing me an error. "

        Quote:

        Cannot implicitly convert type 'void' to 'System.Windows.Forms.DialogResult

        public partial class Main : Form
        {
            public Main()
            {
                InitializeComponent();
            }
        
        
            private void Main\_Load(object sender, EventArgs e)
            {
                if(!File.Exists(Directory.GetCurrentDirectory() + "\\\\Tracker.db"))
                {
                    this.Enabled = false;
                    
                    CreateDB dbForm = new CreateDB();
                    DialogResult res = dbForm.ShowDialog(); //dbform error
        
                    if (res == DialogResult.Cancel)
                        Application.Exit();
                }
            }
        }
        

        public partial class CreateDB : Form
        {
        public event EventHandler CancelPressed;

            public CreateDB()
            {
                InitializeComponent();
                           
            }
        
            private void Cancel\_Click(object sender, EventArgs e)
            {
                if (CancelPressed != null)
                    CancelPressed(this, EventArgs.Empty);
            }
        }
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #12

        Your CreateDB form needs to return a valid DialogResult. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].

        U 1 Reply Last reply
        0
        • L Lost User

          Your CreateDB form needs to return a valid DialogResult. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].

          U Offline
          U Offline
          Uranium 235
          wrote on last edited by
          #13

          private void Cancel_Click(object sender, EventArgs e)
          {
          //if (CancelPressed != null)
          // CancelPressed(this, EventArgs.Empty);

                  return DialogResult.Cancel;
              }
          

          I returned a DialogResult now I get Since 'TechTracker.CreateDB.Cancel_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression and yeah I tried changing void to DialogResult and it gave me an error on the form

          L 1 Reply Last reply
          0
          • U Uranium 235

            private void Cancel_Click(object sender, EventArgs e)
            {
            //if (CancelPressed != null)
            // CancelPressed(this, EventArgs.Empty);

                    return DialogResult.Cancel;
                }
            

            I returned a DialogResult now I get Since 'TechTracker.CreateDB.Cancel_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression and yeah I tried changing void to DialogResult and it gave me an error on the form

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

            The Cancel_Click is a delegate type, so it cannot return a value. It handles an event and then returns to the framework. You need to return your DialogResult from the main method of the form. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].

            U 1 Reply Last reply
            0
            • L Lost User

              The Cancel_Click is a delegate type, so it cannot return a value. It handles an event and then returns to the framework. You need to return your DialogResult from the main method of the form. See Form.ShowDialog Method (System.Windows.Forms) | Microsoft Docs[^].

              U Offline
              U Offline
              Uranium 235
              wrote on last edited by
              #15

              ok I get it, so I didn't even need cancel_click (this is a delegate, right?) at all since the DialogResult was already cancel in the form properties.

              L 1 Reply Last reply
              0
              • U Uranium 235

                ok I get it, so I didn't even need cancel_click (this is a delegate, right?) at all since the DialogResult was already cancel in the form properties.

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

                Correct.

                1 Reply Last reply
                0
                • U Uranium 235

                  It was so simple in VB, accessing other forms properties. The main form, right after it's drawn, I want to check for a .db file and if it dosen't exist, to make visible a form (already defined) to create it the db file. (form already as always-on-top, but not visible). After a ton of internet research, i'm still where I started. Closest I got gave me a threading error, which I've learned to work around in VB, but this, is just confusing (TechTracker.CreateDB.ActiveForm.Visible = true;) I like how much c# is to PHP AFA structure, loops, arrays, strings. But this stuff is confusing me

                  U Offline
                  U Offline
                  Uranium 235
                  wrote on last edited by
                  #17

                  ok, been working on it, i'd figure i'd just add to this instead of making a new thread. I've been messing with SQLite. What I want is to make a function to run the query, get row data and return it. Of course, rows are of mixed types, Using GetDataTypeName(), but storing these into an array is impossible because arrays can only be one type is there a way to store the row data into an array? I've tried the reader row data itself, but i'm not sure i'm going about it the right way this is the core section i'm trying. I've successfully done the query and got the data inside the function, just returning it is the problem

                  sqlite\_cmd = sql\_conn.CreateCommand();
                  sqlite\_cmd.CommandText = sql\_query;
                  sqlite\_datareader = sqlite\_cmd.ExecuteReader();
                  
                  SQLLiteReader Row\[\];
                  
                  
                  //store reader data in an array?
                      for(int i = 0; sqlite\_datareader.Read(); i++)
                      {
                              Row\[i\] = sqlite\_datareader;
                      }
                  

                  and return the row. I tried passing the reader up by reference but that was unsuccessful My error: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

                  U 1 Reply Last reply
                  0
                  • U Uranium 235

                    ok, been working on it, i'd figure i'd just add to this instead of making a new thread. I've been messing with SQLite. What I want is to make a function to run the query, get row data and return it. Of course, rows are of mixed types, Using GetDataTypeName(), but storing these into an array is impossible because arrays can only be one type is there a way to store the row data into an array? I've tried the reader row data itself, but i'm not sure i'm going about it the right way this is the core section i'm trying. I've successfully done the query and got the data inside the function, just returning it is the problem

                    sqlite\_cmd = sql\_conn.CreateCommand();
                    sqlite\_cmd.CommandText = sql\_query;
                    sqlite\_datareader = sqlite\_cmd.ExecuteReader();
                    
                    SQLLiteReader Row\[\];
                    
                    
                    //store reader data in an array?
                        for(int i = 0; sqlite\_datareader.Read(); i++)
                        {
                                Row\[i\] = sqlite\_datareader;
                        }
                    

                    and return the row. I tried passing the reader up by reference but that was unsuccessful My error: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

                    U Offline
                    U Offline
                    Uranium 235
                    wrote on last edited by
                    #18

                    oh duh I needed to specify 'Array' but now I get

                    Array SQLLiteReader Row[];
                    ^^^
                    "; expected"
                    ^
                    identifier expected

                    U 1 Reply Last reply
                    0
                    • U Uranium 235

                      oh duh I needed to specify 'Array' but now I get

                      Array SQLLiteReader Row[];
                      ^^^
                      "; expected"
                      ^
                      identifier expected

                      U Offline
                      U Offline
                      Uranium 235
                      wrote on last edited by
                      #19

                      wait a second I used this

                      DataTable returnTable = new DataTable();
                      DataColumn dtColumn;
                      DataRow dataRow;

                              MessageBox.Show(fieldCount.ToString());
                      
                              for (int i = 0; i <= (fieldCount - 1); i++)
                              {
                                  //MessageBox.Show(sqlite\_datareader.GetDataTypeName(i));
                      
                                  switch (sqlite\_datareader.GetDataTypeName(i))
                                  {
                                      case "TEXT":
                                          dtColumn = new DataColumn();
                                          dtColumn.DataType = typeof(String);
                                          dtColumn.ColumnName = sqlite\_datareader.GetName(i);
                                          returnTable.Columns.Add(dtColumn);
                                      break;
                      
                                      case "INTEGER":
                                          dtColumn = new DataColumn();
                                          dtColumn.DataType = typeof(Int32);
                                          dtColumn.ColumnName = sqlite\_datareader.GetName(i);
                                          returnTable.Columns.Add(dtColumn);
                                      break;
                                  }
                              }
                      
                      
                      
                              for (int j = 0; sqlite\_datareader.Read(); j++)
                              {
                                  for (int k = 0; (k <= fieldCount - 1); k++)
                                  {
                                      MessageBox.Show(sqlite\_datareader.GetDataTypeName(k));
                                      MessageBox.Show(sqlite\_datareader.GetName(k));
                      
                                      switch (sqlite\_datareader.GetDataTypeName(k))
                                      {
                      
                                          case "TEXT":
                                              dataRow = returnTable.NewRow();
                                              dataRow\[sqlite\_datareader.GetName(k)\] = sqlite\_datareader.GetString(k);
                                              returnTable.Rows.Add(dataRow);
                                              //returnTable.Rows.Add(sqlite\_datareader.GetString(k));
                                              break;
                      
                                          case "INTEGER":
                                              dataRow = returnTable.NewRow();
                                              dataRow\[sqlite\_datareader.GetName(k)\] = sqlite\_datareader.GetInt32(k);
                                              returnTable.Rows.Add(dataRow);
                                              //returnTable.Rows.Add(sqlite\_datareader.GetString(k));
                                              break;
                                      }
                      
                                  }
                                    \*/
                      

                      to try to load the query into a datatable (unsuccessfully, datatype problems), and you can just use .load()? That was a day well wasted

                      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