zachattack05 70 Posting Pro in Training

Does anyone have any suggestions for a site that hosts bug tracking? Preferably free, and one that doesn't ask for phone numbers?

I'd like to have something that is hosted online so that users can submit bugs. And also so that I can track them anywhere I decide to work (office, home, coffee shop, bathroom, basement, street...you get the idea)

Suggestions?

zachattack05 70 Posting Pro in Training

I opted to go the route of delegates. Seems more natural for me to do that. Guess it just fits my personal style.

zachattack05 70 Posting Pro in Training

I tend to use a global collection that has message objects put in it by MDIChild forms. The message objects have a message and a timeout value.
The MDIparent form then uses a timer to examine the collection and cycle the messages on the status bar and remove messages when the timeout expires.
This has the advantage that many MDIchild forms can send different status messages and no message is lost.

Hmmm....not a bad idea but might be more complex than what I need. Having messages lost isn't a major problem that I can foresee....Though I could be wrong...If two child forms are performing separate tasks at the same time, both of which involve updating the status bar...I don't see it as a big deal. The status bar simple displays messages that are simple such as "Refreshing data..." or "Checking connection..." nothing that a user would need to rely on. It's simply there for piece of mind that the software hasn't taken a dive.

zachattack05 70 Posting Pro in Training

All parenting jokes aside, I have a general purpose status strip on my parent form that contains a progress bar and a few labels.

Occasionally a child form will execute a command that could be tracked on the status bar so my users don't think that the program is hanging...

I searched around and this topic seems to be open for quite a bit of debate. Some say use delegates, some say to set properties and some say to simply set the value of the control by name.

What's your thoughts? I'm looking for something that will be easy to update and maintain as well as easy to implement as a parent form can have multiple child forms.

Here are the suggestions I have run across so far:

Simply type:

this.ParentForm.Controls["label1"].Text="HI..."

Seems sloppy though and probably a nightmare to keep track of.

The other option, which might be the best -- but not sure, is from the DaniWeb web site: Update label text from another thread.

And finally this:

//IN THE CHILD FORM (MDIChild)

        private void button1_Click(object sender, EventArgs e)
        {
            MDIParent oParent = ParentForm as MDIParent;
            oParent.ChangeParentText = "My cool text";
        }
//IN THE PARENT FORM (MDIParent)

        public string ChangeParentText 
        {
            get
            {
                return label1.Text;
            }
            set 
            {
                label1.Text = value;
            }
        }

Any suggestions? What would be the preferred method for achieving this?

zachattack05 70 Posting Pro in Training

You can use typed datasets generated by the IDE or use an entity framework, ie: nhibernate, developer express' XPress Persistent Objects (XPO), or .. a handful of other libs. Take a look around at entity frameworks. There is a lot to learn.

Thanks. I'll take a look and see what I can find. Any preferences?

zachattack05 70 Posting Pro in Training

>I am thinking of, then I am WAY lost.

I would like to say that keep your program as simple as you can do. It's very difficult to develop simple programs.

I understand that...I'm just wondering if there is a way to make something like this:

SqlCommand cmd = new SqlCommand(updatestring, Connection);

            //set our parameters
            cmd.Parameters.Add(new SqlParameter("@companycode", (object)companycode.Text));
            cmd.Parameters.Add(new SqlParameter("@title", (object)title.Text));
            cmd.Parameters.Add(new SqlParameter("@firstname", (object)firstname.Text));
            cmd.Parameters.Add(new SqlParameter("@lastname", (object)lastname.Text));
            cmd.Parameters.Add(new SqlParameter("@company", (object)company.Text));
            cmd.Parameters.Add(new SqlParameter("@physicaladdress", (object)physicaladdress.Text));
            cmd.Parameters.Add(new SqlParameter("@physicalcity", (object)physicalcity.Text));
            cmd.Parameters.Add(new SqlParameter("@physicalstate", (object)physicalstate.Text));
            cmd.Parameters.Add(new SqlParameter("@physicalzip", (object)physicalzip.Text));
            cmd.Parameters.Add(new SqlParameter("@mailingaddress", (object)mailingaddress.Text));
            cmd.Parameters.Add(new SqlParameter("@mailingcity", (object)mailingcity.Text));
            cmd.Parameters.Add(new SqlParameter("@mailingstate", (object)mailingstate.Text));
            cmd.Parameters.Add(new SqlParameter("@mailingzip", (object)mailingzip.Text));
            cmd.Parameters.Add(new SqlParameter("@billingcontact", (object)billingcontact.Text));
            cmd.Parameters.Add(new SqlParameter("@billingaddress", (object)billingaddress.Text));
            cmd.Parameters.Add(new SqlParameter("@billingcity", (object)billingcity.Text));
            cmd.Parameters.Add(new SqlParameter("@billingstate", (object)billingstate.Text));
            cmd.Parameters.Add(new SqlParameter("@billingzip", (object)billingzip.Text));
            cmd.Parameters.Add(new SqlParameter("@phone", (object)phone.Text));
            cmd.Parameters.Add(new SqlParameter("@fax", (object)fax.Text));
            cmd.Parameters.Add(new SqlParameter("@faxsecure", (object)faxsecure.Checked));
            cmd.Parameters.Add(new SqlParameter("@email", (object)email.Text));
            cmd.Parameters.Add(new SqlParameter("@mro", (object)mro.Text));
            cmd.Parameters.Add(new SqlParameter("@reportingmethod", (object)reportingmethod.Text));
            cmd.Parameters.Add(new SqlParameter("@primarylab", (object)primarylab.Text));
            cmd.Parameters.Add(new SqlParameter("@primarylabaccountnumber", (object)primarylabaccountnumber.Text));
            cmd.Parameters.Add(new SqlParameter("@secondarylab", (object)secondarylab.Text));
            cmd.Parameters.Add(new SqlParameter("@secondarylabaccountnumber", (object)secondarylabaccountnumber.Text));
            cmd.Parameters.Add(new SqlParameter("@filedate", (object)filedate.Text));
            cmd.Parameters.Add(new SqlParameter("@safetydirector", (object)safetydirector.Text));
            cmd.Parameters.Add(new SqlParameter("@alternatecontacts", (object)alternatecontacts.Text));
            cmd.Parameters.Add(new SqlParameter("@agency", (object)agency.Text));
            cmd.Parameters.Add(new SqlParameter("@clinic", (object)clinic.Text));
            cmd.Parameters.Add(new SqlParameter("@filename", (object)filename.Text));
            cmd.Parameters.Add(new SqlParameter("@lastupdated", DateTime.Now));
            cmd.Parameters.Add(new SqlParameter("@randompool", (object)randompool.Text));
            cmd.Parameters.Add(new SqlParameter("@drugrate", (object)drugrate.Text));
            cmd.Parameters.Add(new SqlParameter("@drugdrawtype", (object)drugdrawtype.Text));
            cmd.Parameters.Add(new SqlParameter("@alcoholrate", (object)alcoholrate.Text));
            cmd.Parameters.Add(new SqlParameter("@alcoholdrawtype", (object)alcoholdrawtype.Text));
            cmd.Parameters.Add(new SqlParameter("@notes", (object)notes.Text));
            cmd.Parameters.Add(new SqlParameter("@active", (object)active.Text));
            cmd.Parameters.Add(new SqlParameter("@rlock", (object)rlock.Checked));

            //run the update query
            Connection.Open();
            MessageBox.Show(cmd.ExecuteNonQuery().ToString() + " rows affected");

Into something a little more manageable and easier to maintain?

The articles you posted seemed to not do what I was wanting to do. And the post by sknake was confusing to me because I have never used a dictionary for anything before. I was hoping he could expand on it based on …

zachattack05 70 Posting Pro in Training

Have a look at these threads :

1. http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
2. http://www.sommarskog.se/arrays-in-sql-2005.html#CSV

adatapost,

I think these links are refering to something different? I could be wrong, but if they are talking about the same thing I am thinking of, then I am WAY lost.

zachattack05 70 Posting Pro in Training

You could use a dictionary to index the controls.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace daniweb
{
  public partial class frmAutoPopulate : Form
  {
    Dictionary<Control, string> bindings;

    public frmAutoPopulate()
    {
      InitializeComponent();
    }

    private void frmAutoPopulate_Load(object sender, EventArgs e)
    {
      bindings = new Dictionary<Control, string>();
      bindings.Add(textBox1, "Name");
      bindings.Add(textBox2, "Adddress");
      bindings.Add(textBox3, "Zip");
      bindings.Add(checkBox1, "Deceased");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
      Control[] ctrls = (Control[])FindControls(this, typeof(Control));
      for (int i1 = 0; i1 < ctrls.Length; i1++)
      {
        Control ctrl = ctrls[i1];
        string name;

        if (!bindings.TryGetValue(ctrl, out name))
          continue; //not in our bindings list
        if ((ctrls[i1] as TextBox) != null)
        {
          cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + name, ((TextBox)ctrl).Text));
        }
        else if ((ctrls[i1] as CheckBox) != null)
        {
          cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + name, ((CheckBox)ctrl).Checked));
        }
      }
    }


    private static Array FindControls(Control ctrl, Type t)
    {
      System.Collections.ArrayList result = new System.Collections.ArrayList();
      foreach (Control c in ctrl.Controls)
      {
        if ((c.GetType() == t) || c.GetType().IsSubclassOf(t))
          result.Add(c);
        foreach (Control childCtrl in c.Controls)
          result.AddRange(FindControls(childCtrl, t));
      }
      return result.ToArray(t);
    }
  }
}

Sknake,

Thanks for your reply! But...you lost me.

Here is a picture of my form and the code behind it...Maybe this might help? Could you possibly expand on your example?

private void Save(object sender, EventArgs e)
        {
            #region Error Handlers

            Messages errors = new Messages();

            #endregion

            #region Connect to Database

            //get default server type
            string ServerType = Properties.Settings.Default.SQLType.ToString();

            //get our connection string
            ConnectionManager ConnectionString = new ConnectionManager();
            string SQLConnectionString = ConnectionString.ConnectionString(ServerType);
            SqlConnection Connection = new SqlConnection();
            Connection.ConnectionString = SQLConnectionString;

            //try opening the …
zachattack05 70 Posting Pro in Training

I have a form that has multiple text boxes, check boxes etc...
The question is, instead of writing out:

cmd.Parameters.Add(new SqlParameter("@myparam", (object)textbox.Text));

a million times for each parameter, is it possible to load all of the names of the objects on a form into an array and just do a loop through those names to set the parameters?

I tried using something similar to:

cmd.Parameters.Add(new SqlParameter("@" + array.GetValue(cnt).ToString(), (object)array.GetValue(cnt).Text));

but for obvious reasons...it fails. Any suggestion? Instead of an array that I populate maybe a system array works that would get the object names off of the form? I dunno...

zachattack05 70 Posting Pro in Training

Zach, CommandBuilder is easier to use. As in it's more GUI oriented less to remember easier to debug. But I prefer string Update, there must a be a trade-off for user-friendliness and performance.

I'm sure string updates take longer, but I think I'll stick with it. I like being able to see what exactly is going on.

Good documentation, comments and regions make things easier to debug...I'll just stick with string updates myself. Just wondering is all.

zachattack05 70 Posting Pro in Training

Does anyone use it?

Seems kind of scary to me the thought that I would allow a mysterious command to alter data in my tables.

Is it better to write your own update strings and execute them or use the command builder? Does it matter?

Edit: PS the new site design is awesome :)

zachattack05 70 Posting Pro in Training

I figured it out.

I placed:
SqlCommand query;
SqlDataAdapter adrQuery;
DataSet dsQuery;
in globals and then just called:

int recordCurrent = int.Parse(DataNavigatorPositionItem.Text) - 1;
            dsQuery.Clear();
            adrQuery.Fill(dsQuery, "accounts");
            bindsrc.Position = recordCurrent;

in any event that I need the recordset to update and it works!

Just in case anyone else had the same problem :)

zachattack05 70 Posting Pro in Training

I think I figured out what I need to do, but....I'm not quite sure how to do it?

I think i need to call adrQuery.Fill(dsQuery, "accounts") again, but since that dataset that needs to be filled again is located in the on_load portion of the form, I can't call it again without recreating the entire data adapter etc... and that just seems like a bad idea?

Any suggestions?

zachattack05 70 Posting Pro in Training

I have been working on a form that reads records from a SQL database. I have the binding working in that it populates all of the fields with the correct data. But if I am viewing record 1 and record 2 changes while I'm looking at 1, then browse to record 2, it shows me the old data unless I close and re-open the form which causes the binding to happen over again with the new data.

Is there a way to have the data in the dataset updated with each record change?

Here is the relevant form code...any suggestions would be greatly appreciated:

public partial class EditorAccounts : Form
    {
        #region Globals

        BindingSource bindsrc;

        #endregion

        public EditorAccounts()
        {
            InitializeComponent();
        }

        #region On Load Events

        private void EditorAccounts_Load(object sender, EventArgs e)
        {

            #region Error Handlers

            Messages errors = new Messages();

            #endregion

            #region Connect to Database

            //get default server type
            string ServerType = Properties.Settings.Default.SQLType.ToString();

            //get our connection string
            ConnectionManager ConnectionString = new ConnectionManager();
            string SQLConnectionString = ConnectionString.ConnectionString(ServerType);
            SqlConnection Connection = new SqlConnection();
            Connection.ConnectionString = SQLConnectionString;

            //try opening the connection
            try
            {
                Connection.Open();
                Connection.Close();
            }
            catch
            {
                //connection failed
                //give error message
                errors.ErrorMessages(004);
            }

            #endregion

            #region Retrieve Data

            try
            {
                SqlCommand query = new SqlCommand("SELECT * FROM accounts", Connection);
                SqlDataAdapter adrQuery = new SqlDataAdapter(query);
                DataSet dsQuery = new DataSet();
                adrQuery.Fill(dsQuery, "accounts");

                bindsrc = new BindingSource(dsQuery, "accounts");

                DataNavigator.BindingSource = bindsrc;

                #region Bindings

                //bind our data to the fields
                //I cut this out of my post because it was forever and …
zachattack05 70 Posting Pro in Training

what do u wnat to do?
do u want to bind data in the same row in a lable?? or do u want to bind to a text box from the database??

I was binding data in a row to a label, but I discovered that I didn't actually need to do that. Nevermind :)

zachattack05 70 Posting Pro in Training

Can you do that?

I can't seem to get it to work.

lblfiledate.DataBindings.Add("Text", bindsrc, "filedate");

Doesn't work.

zachattack05 70 Posting Pro in Training

Oh!

I didn't notice. The only forum I visit is C# and I guess there aren't any for that forum :(

zachattack05 70 Posting Pro in Training

I think it would be nice if we had forums for people to contribute tutorials that they have written.

Searching through the forums doesn't always result in a complete picture of a problem a particular person may be having. Tutorials might help a lot!

Any thoughts?

zachattack05 70 Posting Pro in Training

That I'm not too sure about. You may want to mess around with the points/dimensions a little bit to see what fits your requirements but mostly what works. You may be able to search for the ratio between application coordinates and actual distance. Print something out, see where it lands on the piece of paper, put the paper back in, oriented differently and try again. There's got to be a way to do it without trial and error, but I don't know how.

I'll see what I can find :)

Thanks! If I figure it out I'll let you know!

zachattack05 70 Posting Pro in Training

http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx

That link should get you to where you could print out the actual form.

As for printing an actual form-like document from an application, there are a couple ways that I can think of to do it, both probably being inefficient as I'm not that good at C# yet.

First, you can design the form in another application like Publisher or InfoPath. Print that out and use that as your paper for printing out form data from your actual form application. It may take you a while to nail down your positioning, but it would work. I know medical offices have applications that do something like this as HCFA forms are done this way many times.

Second, you could spend some time designing the form using the printing framework.

void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawLine(new Pen(Color.Aqua, 2.0), new Point(5, 3), new Point(10, 6));
    e.Graphics.DrawRectangle(new Pen(Color.Azure), 250, 65, 20, 15);
    e.Graphics.DrawString(textBox.Text, new Font("Times New Roman", 12), Brushes.Bisque, 250, 65);
    ...
}

That's a ton of help! Thank you!

One quick question though....you are referencing points to draw lines and other graphics....what are those referenced to? That seems to be my biggest hold up.....is there a piece of paper I can print out that shows points of reference so that I can hand draw my form and then enter the points of reference? I guess what I am after is the "resolution" of the paper...is that something that can be set?

zachattack05 70 Posting Pro in Training

Have you tried just Googling "C# Printing"? Seems there's a lot of good results from that.

Yep. Been there, tried that, consumed aspirin to relieve headache and repeated ad nauseum...

The thing I don't get is how to create forms that don't just contain text. All of the examples that I have read deal with text only, setting margins and fonts and page orientation...that's wonderful and great. But what about drawing lines? Creating a box 4 inches from the left margin and 6 inches from the right where the top and bottom is 2 inches and the sides are 1? Then filling that box with text, or an image or whatever else?

The tutorials are all so basic and don't cover any of those things, at least not the ones I have found. The ones that might touch on it are from 7 years ago and are poorly written.

If no one has a link, is there a good book that might touch on this subject?

Attached is an image of a printed form. I need my application to print something similar to this. (confidential info blocked out).

Any help?

zachattack05 70 Posting Pro in Training

Anyone have any good links to tutorials for printing with C#?

I need to mimic a form that we have. It's a rather complex form, so if you know of a tutorial that is better than just printing rows and columns of data would be greatly appreciative!

zachattack05 70 Posting Pro in Training

I think there is too much transaction going to your database, you have the idea already but I think there will be even more better design than this. Technically I don't want my database to do all the work for me specially on the locking part. I guess if you can create another app that monitors the locked documents , something like a client-server setup application , then I think it will be a lot faster and you can actually patch up some logic behind it.

I think your solution will help you out as your initial proof of concept. Try it first because you will never know if it really works the way you want it and experienced it.

I can't push my suggestions to you since you're actually the one doing the programming part and not me, hope you can solved your problem the soonest possible time.

I can see where there could potentially be quite a few transactions going to the database...but having a second piece of software installed on the SQL server could complicate things.

Do you think that there would be much of a performance impact on either the SQL server itself or the application? Or is it the design that concerns you?

zachattack05 70 Posting Pro in Training

OK, I think I may have an idea. Let me know what you guys think:

Have a separate SQL table on my database called "locks" or something.

In that table have these columns:
id - Auto Inc. Integer field (for sorting mostly)
table - holds the name of the table that has a lock
record - holds the record id number of the record that is locked/requested
status - can either be "locked" or "queued"
user - contains the name of the user that has the record locked or is requesting the record
expires - holds a randomly generated number that changes every 60 seconds

This table would allow for a queue for records, so if user A is editing record 50 and user B needs to edit it, they would essentially click a button or something that would check the locks table for that particular record id and see if it is locked, if it is, it will add their name to the locks table with the status of queued.

The form would also have a timer function on it set to 60 seconds. Every 60 seconds the client that has the record locked would generate a random number and update the locks form with that number in the expires column. Every 60 seconds the client that is waiting for the record to be unlocked would check to see if the number in expires changed, if it did then …

zachattack05 70 Posting Pro in Training

If you're using MS SQL server then you can use its notification services to prompt users that there has been an update. Now its up to your client to keep up on it and how such updates will be interpreted.

You can also go with the time stamp logic but I suggest you have only 1 app that will update your database. Let that app queue up your transactions and if there is a probable error you can then notify the client that its data is not recent anymore.

I suggest that you read on disconnected distributed application and how it is done.

The problem is I am trying to avoid human error. The system that I am designing could potentially hold medical record information for small clinics. I would want to prevent user A from getting a message saying that the data they are looking at is outdated and to refresh it. If I go with a system like that, then if user A is working in a certain recordset and user B makes a small change, then user A may have to re-enter all of their information if they refresh it. I would rather simply prevent two people from editing a record at the same time instead of fielding data collisions when they happen. See what I mean?

zachattack05 70 Posting Pro in Training

I think what I'm going to do is have a record locking system. I'll have the locking computer post a updated time stamp every 5 minutes or so, if a different computer requests to lock the record and the time stamp is more than 5 minutes old I'll have that new requesting computer unlock it and then re-lock it with the new credentials in case there is a failure or something.

Only issue I can see with this is each computer having a different clock. If computer A is 5+ mins faster it can mess up the system...I may need a program on the SQL Server computer to manage locked records....hmmmm

Any other ideas?

zachattack05 70 Posting Pro in Training

As always with this stuff, there are many ways to skin the proverbial cat. Using the timestamp method, you could even go as far as this: when you attempt to apply the update but find the record's been updated under you, re-read it into another buffer and compare the appropriate values, highlighting any differences and display to the user. Of course, that's a lot of elbow grease. More simply, you could just put a message out to the user saying "Another user has updated the record; please re-enter your changes" and re-display the form to the user with the new values from the newly-updated record.

Hmmm...that's not a bad idea, but your right it does sound like a pain in the rear. The big problem is that sometimes a user might enter a lot of information, a paragraph or so. That would suck to have to re-enter a paragraph again if it is just deleted.

Anyone else have any suggestions? Nothing seems to stick out to me too much, but I do think that the time stamp idea is the best. I just want to make sure that it is easy for the end user to use.

zachattack05 70 Posting Pro in Training

One simple way is to use a DateTime or Timestamp column. When you update the row, check the timestamp to see if it matches the value you got when you pulled the record for editing. If it does not match, you know someone else updated the record while you were working on it.

Good idea. But that leads me into the direction of a corner. If I compare the value displayed on workstation1 to the value stored in the SQL server and the values match there's no problem. Simply update the record and change the time stamp. But what if the values are different? Do I just say to the user that the changes cannot be saved because the record was changed by someone else first? Do I offer the user the opportunity to overwrite the changes, revert to the new changes etc...

If I offer a record checkout or record locking system then if user X edits the record and user Y tries to at the same time, user Y gets a message saying the record is already locked for editing.

I think there are downsides to locking records too...for example, software crashes, network interruptions etc...can leave records permanently checked out making them uneditable unless someone updates the record manually.

I think I like the time stamp idea you proposed better, but I'm not sure how to handle it when two users attempt to update the record.

zachattack05 70 Posting Pro in Training

Thanks to you guys I have been able to get my first application halfway going. But I have a question about data integrity.

The application that I am developing utilizes a single sql server and multiple work stations accessing that sql server.

What is the best way to maintain data integrity? If user X is editing record 20 and user Y is editing record 20 at the same time, whoever saves the data last wins. That's not a good plan.

I was thinking about having records "locked" when they are edited, or something similar to that. Maybe making all records read-only unless you "check out" the record for editing....how have you guys handled this in your applications?

zachattack05 70 Posting Pro in Training

adatapost,

That works beautifully! Thank you!

zachattack05 70 Posting Pro in Training

I'm lost. I've been trying to do this for a while now and I can get halfway what I need. But I can't tell if it's working or not, or where my problem is.

I don't want to use the wizard in VS to add a data source, I'd like to do it all programmatic and I would like my users to be able to browse, edit, add and delete data in a SQL database in a similar way that MS Access works.

This is what I have so far:

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.SqlClient;

namespace Information_Database_Control_Center
{
    public partial class EditorAccounts : Form
    {
        BindingSource bindsrc = new BindingSource();

        public EditorAccounts()
        {
            InitializeComponent();
        }

        #region On Load Events

        private void EditorAccounts_Load(object sender, EventArgs e)
        {
            #region Error Handlers

            Messages errors = new Messages();

            #endregion

            #region Connect to Database

            //get default server type
            string ServerType = Properties.Settings.Default.SQLType.ToString();

            //get our connection string
            ConnectionManager ConnectionString = new ConnectionManager();
            string SQLConnectionString = ConnectionString.ConnectionString(ServerType);
            SqlConnection Connection = new SqlConnection();
            Connection.ConnectionString = SQLConnectionString;

            //try opening the connection
            try
            {
                Connection.Open();
                Connection.Close();
            }
            catch
            {
                //connection failed
                //give error message
                errors.ErrorMessages(004);
            }

            #endregion

            #region Retrieve Data

            try
            {
                SqlCommand query = new SqlCommand("SELECT * FROM accounts", Connection);
                SqlDataAdapter adrQuery = new SqlDataAdapter(query);
                DataSet dsQuery = new DataSet();
                adrQuery.Fill(dsQuery);

                bindsrc.DataSource = dsQuery;

                DataNavigator.BindingSource = bindsrc;

                companycode.DataBindings.Add("Text", bindsrc, "companycode");
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }

            #endregion
        }

        #endregion
    }
}

No …

zachattack05 70 Posting Pro in Training

Maybe I'm just not sure what code exactly you want me to post?

Is there somewhere that shows an example of using a SQL SELECT statement with a binding navigator?

zachattack05 70 Posting Pro in Training

Any suggestions? Or did I lose everyone?

zachattack05 70 Posting Pro in Training

I think it would actually be really appreciated :)

Sure...

The VBA code that is used on the account editor has nothing to do with navigating records though, but here is what source there is:

Option Compare Database

Private Sub cmdAddressCopy_Click()

'make sure the user isn't stupid

Dim intConfirm As Integer

intConfirm = MsgBox("Are you sure you wish to copy the physical address to the " & _
    "mailing address?" & vbCr & vbCr & "This cannot be undone.", vbYesNo, _
    "Confirm Address Copy")
   
If intConfirm = 7 Then
    GoTo lblStop
End If

Me.txtMailingAddress = Me.txtPhysicalAddress
Me.txtMailingCity = Me.txtPhysicalCity
Me.txtMailingState = Me.txtPhysicalState
Me.txtMailingZip = Me.txtPhysicalZip

lblStop:

End Sub

Private Sub cmdContractBuilder_Click()
    i = ContractBuilder(txtCompanyCode, Right(txtPrimaryLabAccount, 4), txtMRO, txtPrimaryLab)
End Sub

Private Sub cmdNavToggle_Click()

If cmdNavToggle = 0 Then
    DoCmd.MoveSize , , 11600, 15600
Else
    DoCmd.MoveSize , , 15840, 15600
End If

End Sub

'--------------------------------------------------------------
'Graham Thorpe 25-01-02
'
'Modified by Zachary Weber 10/23/2009
'--------------------------------------------------------------
Private Sub cmdSearch_Click()

'Update Completed for Ver. 2.1X on 08/11/09

    Dim strCompanyRef As String
    Dim strSearch As String
    
'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
        Me![txtSearch].SetFocus
    Exit Sub
End If
'---------------------------------------------------------------
        
'Performs the search using value entered into txtSearch
'and evaluates this against values in txtCompanyCode
        
    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("txtCompanyCode")
    DoCmd.FindRecord Me!txtSearch
        
    txtCompanyCode.SetFocus
    strCompanyRef = txtCompanyCode.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text
        
'If matching record found sets focus in txtSearch and shows msgbox
'and clears search control

    If strCompanyRef …
zachattack05 70 Posting Pro in Training

>Can that be done?

Yes. Post your code please.

Not sure what code to post, I am working on creating a record editor, similar to an MS access form that navigates through a filtered set of records.

I don't have any code really on the record editor yet, it's a blank form. I wanted to figure out how I was going to let the users navigate before I got to into it and had a problem that needed to be fixed. Using the binding navigator would be the easier route, just wondered how I would get the binding navigator to update the fields. I'm used to using record sets and stuff in VBA, but that's not available here as far as I know, Otherwise I could simply use something like movenext or whatever and then update all of the text fields with the new data. The record set of course containing id numbers for fields in the tables...

I have some vba code that I would like to basically convert to C#, I can't figure out how to do it, so the closest I could find (I think) is a binding navigator.

I can post my VBA code if you want, or if that would help, but I somehow doubt it would?

zachattack05 70 Posting Pro in Training

What about with specific SQL queries? Like: SELECT * FROM accounts WHERE id = [some variable];?

Can that be done?

zachattack05 70 Posting Pro in Training

Good evening!

I was hoping someone could help me here. I've been teaching myself C# for quite a while now, and I'm working on a project and have run into a problem.

I would like to use the binding navigator control to allow my users to browse through various tables, recordsets etc... the problem is C# wants me to set up a datasource to use that control...I can't really do this because I am allowing the user to decide on their own what data source they want to view. They could make a custom table outside of the program and then just point the program to the correct table by changing some settings in the program.

Is there a way to use the binding navigator control WITHOUT setting up a datasource using the wizard?

I would appreciate any input...I'm at a total loss here.

zachattack05 70 Posting Pro in Training

Very nice! I think I'll use that! Thanks guys!

To expand on what adatapost said, you can search the Application.OpenForms collection by name:

frmEditorAccounts Accounts = Application.OpenForms["frmEditorAccounts "] as frmEditorAccounts

Also, depending on how you have designed your forms, you may want to alter the WindowState of the form as well as bringing it to the front and activating it. If the form is minimised it wont appear when you activate it. Heres a rough idea:

frmEditorAccounts accounts = Application.OpenForms["frmEditorAccounts"] as frmEditorAccounts ;
            if (accounts != null)
            {
                accounts.WindowState = FormWindowState.Normal;
                accounts.BringToFront();
                accounts.Activate();
            }
            else
            {
                accounts = new frmEditorAccounts ();
                accounts.MdiParent = this;
                accounts.Show();
            }
zachattack05 70 Posting Pro in Training

I've been having problems figuring out a way to do this. I need it so that if the user opens form a and then later on buries that form under others, and they click the menu to open the form again that it just sets focus to it instead of opening another instance...

This is what I have now, is there a better, more elegant way of doing this or is this pretty much it?

//see if the form is already open, if it is, set focus to it, if not, open it
            foreach (Form a in MdiChildren)
            {
                if (a is frmEditorAccounts)
                {
                    //the form is open, set focus to it
                    a.BringToFront();
                    a.Activate();
                    break;
                }
            }
            if (ActiveMdiChild == null || ActiveMdiChild.Name != "frmEditorAccounts")
            {
                //no forms are open
                //open one
                frmEditorAccounts Accounts = new frmEditorAccounts();
                Accounts.MdiParent = this;
                Accounts.Show();
            }
zachattack05 70 Posting Pro in Training

Take a look at - http://www.symantec.com/connect/articles/install-and-configure-sql-server-2008-express

That works, but it requires user interaction and instruction for the end user. Which means support calls and troubleshooting for people that really don't need it. I'd like to have it automated. I plan on distributing my solution on a CD or in a compressed file (ie .zip) and will have my own setup package that will copy files and install supporting software.

I will try using sknakes suggestion of using setup.exe /qb ADDLOCAL=SQL_Engine,SQL_Data_Files,SQL_Replication,Client_Components,Connectivity,SQL_SSMSEE INSTANCENAME=InstanceName SAVESYSDB=1 SQLBROWSERAUTOSTART=1 SQLAUTOSTART=1 AGTAUTOSTART=1 SECURITYMODE=SQL SAPWD=password DISABLENETWORKPROTOCOLS=0 ERRORREPORTING=1 SQMREPORTING=0 ADDUSERASADMIN=1 INSTALLSQLDIR="%ProgramFiles%\Microsoft SQL Server\" when I run the install for the server. My question I guess is, can I enable the sa account at install or can I do it programatically with C# after it is already installed?

I'd like to have the SQL server installed and configured "quietly."

zachattack05 70 Posting Pro in Training

It's been a while since I've posted. Things have been going well for my project, but I'm coming back to the issue of setting up a SQL server on my user's computers.

Sknake was kind enough to give me the command line switches to get a MSSQL install set up in a good direction. The problem is that in the 2008 express version the sa user is disabled by default. If I assign it a password at install does it automatically enable the account? If not, I can't log in with it because it is disabled.

I would like to include with my software a user control panel interface for admins that allows server and network admins the ability to create, delete and modify user permissions on the SQL server. But I cannot do that without the sa account enabled. I know I can use windows authentication, but I'd prefer not to. I don't know enough about it to feel confident enough to use it.

My question is: is it possible to enable the sa user on install? If not, how can it be enabled using C# code or will the user have to enable it manually?

zachattack05 70 Posting Pro in Training

>>Add a dialog? When I "publish" the application I don't seem to have any way to add any dialogs...I'm using express edition of C#...figured I shouldn't invest in the full studio until I'm sure I want to do this. See the attachment, that's the screen I see when I publish.

Is this a web app or a windows form app?

>>How would I execute that in C#? Using a ExecuteNonQuery() command?

No that is a parameter to the command-line installation of SQL server. See the setup.exe ? That is run from a command prompt in the same directory as the installer.

This is a windows form app.

I'll think about the user thing later...

zachattack05 70 Posting Pro in Training

See the attachment

Helps if I attach it. :)

zachattack05 70 Posting Pro in Training

Don't add SQL-Server as a launch condition or prerequisit in order to install your software. In the install dialogs add an optional step for installing SQL server, and add an optional step for configuring the database. You don't want to end up making your installer require SQL server for every installation because you only need one SQL instance per network. This will leave /some/ thinking to the person doing the install but it is unavoidable. Keep all of your database setup logic outside of the MSI. It will never work the way you want and it will always be problematic.

Add a dialog? When I "publish" the application I don't seem to have any way to add any dialogs...I'm using express edition of C#...figured I shouldn't invest in the full studio until I'm sure I want to do this. See the attachment, that's the screen I see when I publish.


The admin account for SQL is "sa" and the password is the one defined with SAPWD=xxxx from the initial installation. You can add users programatically in SQL. It would look something like this:

How would I execute that in C#? Using a ExecuteNonQuery() command?

Only if you don't use parameterized SQL. Reference the following URLs:
Daniweb search
http://www.daniweb.com/forums/post1083454.html#post1083454

That should get you started. Never find yourself in the position of adding user-input directly in to a queries' command text.

Excellent! That is a great way to handle that! You learn something new every day! …

zachattack05 70 Posting Pro in Training

Okay, I do have a couple of initial questions after chewing on this for a while...

1) In regards to the application installation and the database being created... If I have only 1 "version" of the application (can be either a client or a server based on how they set the software up), when the msi package runs, it would try to create a blank database on the local system, but the SQL server won't be installed, will that cause the install to fail or can I have it simply ignore the error? Also, what happens if it is a re-install? The database already exists and the user is trying to reinstall the software...are there ways to access how msi packages handle these or would it be better to write my own installer package and do all of this stuff by hand? I hate not having control of how things are handled...the unknown to me makes me nervous.

2) Regarding users on the SQL Server...can users be added programmatically with C# or does the server administrator need to do that through a different interface? Since the server already has an admin account by default...what in the world is the username and password for it considering that I was never asked to set it? I'm assuming "SAPWD=password" is where I would set the admin password and the user name is probably "admin" or something when I install it through a command line right?

3) Injection attacks...is this something …

zachattack05 70 Posting Pro in Training

Sknake,

Let me chew that over for a bit and see if I can wrap my brain around it...you are correct though, the Access project is functioning, but does have issues...that's why I'd like to port it over to C#...I've toyed with the idea of possibly trying c++ instead, but I'm starting to think, at this point, it doesn't really matter...C# should be sufficient for it...besides from what I hear C++ is really no better.

Anyway, let me think about this stuff for a bit...I'm sure I'll have some other questions but I don't know...I might need to just start working on it and if I run into some issues ask then. I'm a pretty picky guy though, I like to know exactly how things work before I mess with it to seriously...maybe that's a bad thing for a noobie programmer to be...

anyway, I'll read your post over a few times and see if anything comes up...thanks again for all of your help and patience!

PS - How do you get those cool looking Mac style buttons on your forms? :P

zachattack05 70 Posting Pro in Training

>>1) The MS SQL Server Express is required to access the data in .mdf files, does the server only need to be installed on the "host" or "server" computer on the network or does it need to be installed on all client computers as well?

You should install the SQL Server on a stable machine and have all of the clients point to that machine. You don't ever need to deal with the raw data files of the SQL Server directly unless you're moving/remounting databases or using a compact edition. For your purposes you should ignore them.

I'm not using the compact edition, but the "Express" edition, so it isn't the "full" version of the software. If I use the "publish" option in C# when I am finished with my application, will it include with it a distributable copy of the SQL Express server or should I instruct my users to download and set-up that software separately? When you write software like this, do you progrmatically mount the database files to the server? Or is that something you have to do manually?

>>2) When a solution uses .mdf files to hold data, how do client computers connect to it? Does it need to be shared (\\server\data\myfile.mdf), does it need to be on a network drive (S:\data\myfile.mdf) or does the client computer need to connect to it using the standard SQL connection (by connecting to IP address ###.###.###.###ORT#)? Or can it be any of those?

You connect to it using …

zachattack05 70 Posting Pro in Training

OK before I fumble around any more and end up needing to change everything again...I was wondering if someone would be kind enough to have a discussion with me about a networked solution.

Right now what I have is an Access database with forms that manage the data...this is great, except deploying such an application is difficult and, in my opinion, unprofessional looking.

I would like to transfer that solution to a C# solution. Here's my main concern:

I need to know how networked applications work (not technically, but with C#)...I know that I need to use an .mdf file (service based database) to achieve this...but before I start working on this any further I was hoping to get the answers to these questions:

1) The MS SQL Server Express is required to access the data in .mdf files, does the server only need to be installed on the "host" or "server" computer on the network or does it need to be installed on all client computers as well?

2) When a solution uses .mdf files to hold data, how do client computers connect to it? Does it need to be shared (\\server\data\myfile.mdf), does it need to be on a network drive (S:\data\myfile.mdf) or does the client computer need to connect to it using the standard SQL connection (by connecting to IP address ###.###.###.###:PORT#)? Or can it be any of those?

3) Does the MS SQL Server Express edition need to be configured in …

zachattack05 70 Posting Pro in Training

Actually nevermind...seems as though I might have to go a different way... I just figured out that sdf files do not allow muli-user access over a network...I'll have to find a different way to store my data :(

zachattack05 70 Posting Pro in Training

Sorry to keep asking so many questions, but you guys always seem to be so nice and helpful...

I need a way to verify that a database file is in a somewhat stable state...stable as in it has all of the correct tables, and each table has all of the correct fields. The data (if any) that is in the database needs to stay unchanged (unless extra tables are present, those would need to be removed).

Thanks to sknake, I think I have a grip on making the tables and columns appear if they are missing...the SQL syntax I am learning, slowly...

The bigger question is, what's the best way to check all of this...I thought about using a list of all the fields and all the tables that should exist and comparing it to the fields that actually do exist by using the FindAll method...the problem is that the solution that I am working on is a copy of a solution that I already made...there are 25 tables and I couldn't even fathom to guess how many fields...if not over 100, pretty close...

I want to be able to check all of this because I'm trying to think ahead with updates...if in the future I want to add a new table, or change a table or merge tables or drop tables from the solution I need a way to do that for users who already have data in their database file...same for those who backup …