« first day  last day (14 days later) » 

12:00 AM
it doesn't
my bad I was testing some things out
fname, ename, companyName
 
what is the error at dv.RowFilter = filter;
 
An exception of type 'System.Data.EvaluateException' occurred in System.Data.dll but was not handled in user code

Additional information: Could not find column [companyName].
 
I get the same name when I change the line... string filter = string.Format("companyName = '{0}'", selectedText);
to be something else than I expect
it should be "companyName = '{0}'", did you change
const string sql = "Select fname, ename, c.companyName AS companyName FROM dbo.Users u inner join dbo.Company c on c.companyName = u.company;";
to have a different column name?
 
no haven't changed the query
so weird...
I unticked the box "break when this exception happens" and it worked
but it showed the exception I had "No companies to display"
    private void companyList_Load(object sender, EventArgs e)
    {
        const string sql = "Select companyName from dbo.Company";
        try
        {
            DataTable dt = selectIntoDataTable(sql);
            companyList.DataSource = dt;
            companyList.ValueMember = "companyName";
        }
        catch (Exception ex)
        {
            MessageBox.Show("There are no companies to display");
        }
    }
 
can you show me the selectIntoDataTable method?
 
12:08 AM
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(cs))
        {
            try
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(sql, con))
                using (SqlDataAdapter a = new SqlDataAdapter(cmd))
                {
                    a.Fill(dt);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
wait
here
    private DataTable selectIntoDataTable(string sql)
    {
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(cs))
        {
            try
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(sql, con))
                using (SqlDataAdapter a = new SqlDataAdapter(cmd))
                {
                    a.Fill(dt);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
 
and you're sure your connection string is correct?
 
yes it is since I'm inserting data. But if I just press OK on the exception box that shows it works and goes to the page
I've got it tested
 
the method seems correct, I just tested it will my own connectionString and it worked
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
DataRowView selectedRow = (DataRowView) companyList.SelectedItem;
string selectedText = (string) selectedRow.Row["companyName"];

DataView dv = dataEmployeesSource.DefaultView;

string column1Name = dataEmployeesSource.Columns[0].ColumnName;
string column2Name = dataEmployeesSource.Columns[1].ColumnName;
string column3Name = dataEmployeesSource.Columns[2].ColumnName;
MessageBox.Show(column1Name + "; " + column2Name + "; " + column3Name, "", MessageBoxButtons.OK);
would you be able to send me all of the code? Might be able to tell like that
 
sure, I'll zip you the proj
its not that big
 
that works, want to email it to me?
 
12:16 AM
sure
whats your email?
 
blakethingstad@hotmail.com
 
I've sent it to you
you should be able to run it towards the azure server, with no need to change connection strings
 
I think I got an older version of your project
the methods have your old code and are missing the new ones I wrote
 
I'll resend
resent
 
everything looks fine except a couple things which I wouldn't think would matter
 
12:28 AM
hmm, like?
 
remove lines 17 and 19 from CompanyForm (the ones with companyList and dataEmployees in them)
they shouldn't be there if they're already declared in the designer
 
True
do you get the exception as well?
When you run it?
 
I'm working on getting it running, I don't have visual studio so I had to rebuild it in my IDE
 
aaah, you're working with linux and vim?
 
windows and SharpDevelop
don't want to pay for Visual Studios
 
12:36 AM
use community?
 
what is that?
 
Visual Studio Community edition
 
and that's free?
 
oh cool
I'll check it out
thanks
 
12:37 AM
you can even crossdevelop apps with it, has integration with xamarin
 
if you change string filter = string.Format("companyName = '{0}'", selectedText);
to string filter = string.Format("company = '{0}'", selectedText);
does it work?
 
same thing
it calls the exception and then crashes, the previous one did not crash
 
try this
string columnName = dataEmployeesSource.Columns[2].ColumnName;
string filter = string.Format("{0} = '{1}'", columnName, selectedText);
 
same exception
An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code
 
on the string columnName row?
line*
 
12:43 AM
yes
dv.RowFilter = filter;
 
then I don't think dataEmployeesSource is getting the data correctly
are you using SQL Server?
 
yes
So it calls the method before it has data
        this.Load += companyList_Load;
        this.Load += dataEmployees_Load;
those are initialized directly
but once it passes the exception it works perfectly fine
 
I guess try putting companyList.SelectedIndexChanged += listbox1_SelectedIndexChanged;
after the Load events
 
same thing, maybe an async on RegisterForm?
exception happens right after you fill out the first form
 
so you're getting that exception without even interacting with the listbox?
 
12:49 AM
yes
it happens before the form is even loaded
 
oh that's odd, shouldn't be getting called until you interact with it
 
well companyList
is called the first thing, it goes to the method, no data and it throws the exception
but passing it, works perfectly fine
 
try this
public CompanyForm()
{
InitializeComponent();

initDataEmployees();
initCompanyList();

companyList.SelectedIndexChanged += listbox1_SelectedIndexChanged;
}

private void initDataEmployees()
{
const string sql = "Select fname, ename, c.companyName AS companyName FROM dbo.Users u inner join dbo.Company c on c.companyName = u.company;";
dataEmployeesSource = selectIntoDataTable(sql);
dataEmployees.DataSource = dataEmployeesSource;
}

private void initCompanyList()
{
const string sql = "Select companyName from dbo.Company";
don't make those methods execute on load, just do it when the form is created
 
ok cool I'll try
cant write

initDataEmployees();
initCompanyList();
it's incorrect syntax it says "Does not exist in current context"
you mean this.DataEmployees
works
<3
maaaaan
that was the problem, load
 
I'm not sure why it was a problem, doesn't seem like it should have been to me
 
12:58 AM
haha we both know now, cant thank you enough
 
but its completely working now?
 
I'm glad I was able to help! I'll update my answer in a sec
 
awesome, man thanks!
 
updated
happy coding!
 
 
19 hours later…
7:51 PM
Accepted your answer :) Thanks again!
 

« first day  last day (14 days later) »