Mitja Bonca 557 Nearly a Posting Maven

1. How to retrieve stored file our of the database?

have stored (for example) a pdf file into database, as a data type of varbinary(MAX) - binary data. How can I get this file back, like it was before?

Important things I have stored for the particular file are:

- ID

- File name

- File type (pdf, word, ... document)

- and of course the content (which is now in binary data)

2. One more small thing:

I would like to get the ID from a Method1 which retrieves the ID, into another Method2 (in the same class), where I will use this ID as a variable.

I have this code for examle:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int IDDocument; //How to get into IDDocument an ID value from the GetID method (from int Doc_ID)
            GetID(IDDocument);  //I got an error here: Use of unassigned local variable 'IDDocument
            string SQL = "SELECT Content FROM Documents WHERE DocumentID = '" + IDDocoment + "'";
            //...
        }

        private void GetID(int Doc_ID)
        {
            string DocID = "SELECT DocumentID FROM Documents WHERE Name = '" + listBox1.SelectedItem + "'";
            SqlCommand cmd = new SqlCommand(DocID, sqlConn);
            cmd.CommandType = CommandType.Text;
            sqlConn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                Doc_ID = reader.GetInt32(0);
            }
            reader.Close();
            sqlConn.Close();
        }
Mitja Bonca 557 Nearly a Posting Maven

How to call a comboBox1_SelectedIndexChanged(object sender, EventArgs e) method from this code:

private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
	{		
		// Get subdirectories from disk, add to treeView1 control
		AddDirectories(e.Node);		

		// if node is collapsed, expand it. This allows single click to open folders.
		treeView1.SelectedNode.Expand();			
		
		// Get files from disk, add to listView1 control
                //IT SHOULD BE HERE!!!
		AddFiles(e.Node.FullPath.ToString());
		statusBar1.Text = iDirectories.ToString() + " Folder(s)  " + iFiles.ToString() + " File(s)";
	}

I have a code there which will Add selected files.

Mitja Bonca 557 Nearly a Posting Maven

Correct. Take a look at this pic: I got 2 values inside an Item:
http://www.file.si/files/bqoc75hwx084p4wz3mmo.jpg"]http://www.file.si/files/bqoc75hwx084p4wz3mmo.jpg"]http://www.file.si/files/bqoc75hwx084p4wz3mmo.jpg

In comboBox1.SelectedItem I have as an Item "AvtoKrka.FilterDatotek" - this is "MyNameSpace.Class_FileFilter". And this I would say is incorect.
I would need to have in selectedItem ONLY DocumentFilter (Filter Dokumenta) which is "*.doc". Don`t you think?

Mitja Bonca 557 Nearly a Posting Maven

I have this code:

string[] dirs = Directory.GetFiles(@"c:\myFolder\", "*.doc");

How do I do the same code, if I change "*.doc" with the comboBox. I have done the code that a user selects a filter from the comboBox.
I did:

string[] dirs = Directory.GetFiles(@"c:\myFolder\", comboBox1.SelectedItem.ToString());

but it is not working... it doesn`t fill the aray dirs (in the 1st upper case it does)!

Mitja Bonca 557 Nearly a Posting Maven

in comboBox even I have:

string myPath = treeView1.SelectedNode.FullPath;
Directory.GetFiles(myPath, comboBox1.SelectedValue.ToString());

and all works fine. I got the path into myPath, and in comboBox1.selectedItem is the FileFilter ("*.doc" in my case).
But it`s not showing the filtered files!!

Maybe is the problem that I need to specify that the files need to show up in the listView. I haven`t specified that in the upper code.

Mitja Bonca 557 Nearly a Posting Maven

The 1st works :) I got the litems into comboBox!
2nd doesn`t, I changed this to:

Directory.GetFiles(comboBox1.SelectedValue.ToString());

But its still not working. Where exactly do I need to put it?

I am doing somekind of an windows explorer, which shows directories and files. Do I put it into the code where the files are added into listView?

Mitja Bonca 557 Nearly a Posting Maven

What I want to do is a drop down list (comboBox) that the user can see only selected files. For example, if user selects a Word Documents from a comboBox, on the explorer will be only visible a doc files.
I have done a FileFilter class:

public class FileFilter
{
    public FileFilter(string name, string filter)
    {
        // Store values
        Name = name;
        Filter = filter;
    }
    public string Name { get; private set; }
    public string Filter { get; private set; }
}

and on the Form1 load I specified the filter available:

Collection<FileFilter> filters = new Collection<FileFilter>();
filters.Add(new FileFilter("Word Documents", "*.doc"));
filters.Add(new FileFilter("Pdf Documents", "*.pdf"));

Now I would like to know how can I fill the comboBox with the Collection of FileFilter objects (with "Word Documents" and "Pdf Documents", and then use the filter on Directory.GetFiles();

If I do on the form_Load:

comboBox1.Items.Add(filter);

it doesn`t show what I want in the comboBox.

Mitja Bonca 557 Nearly a Posting Maven

I have a database, which has atable called Company. Inside are columns with the basic informations (company name, street, post, city, tel.numbers, ...).
I would like to know to populate listBox with company names which have a "stationary number" in the database when checkBox is checked!
But I mean if the column "StationaryNumber" is NULL, then this comany shouldn`t be included in the listBox, if the company has a number (column is NOT NULL) then the name of the is company MUST be incuded in the listBox!

I have this example for a textBox:
cmd.Parameters.Add(new SqlParameter("@stationary", System.Data.SqlDbType.VarChar, 40, "Stationary"));
cmd.Parameters["@stationary"].Value = textBox.Text;

..let` say if I write in the textBox a telephone number which is in the StationaryNumber column,
it will populate the listBox with the companies which have this number(it should be just one company).


But, if I want to put a checkBox like:
cmd.Parameters.Add(new SqlParameter("@stationary", System.Data.SqlDbType.VarChar, 40, "Stationary"));
cmd.Parameters["@stationary"].Value = ??; //OR this whole row is wrong - it has to be bind to the "Stationary" Column somehow.

... How to code these 2 last lines that the readed will read from a database (column "StationaryNumber")
... What has to be instead of ??? to get into my listBox all the company names,
which have the telephone number in Stationary column


For a better idea what I am doing, take a look at THIS picture. In the buttom …

Mitja Bonca 557 Nearly a Posting Maven
DataGridViewCell c = (DataGridViewCell)dataGridView1.SelectedRows[0].Cells[0];

And how can I fill Rows[0].Cell[0] if I dont know them? With mouse click (currentCell method) will be known which cell and row is selected.
Any idea how to work this out?

Mitja Bonca 557 Nearly a Posting Maven

I have created my own dataset: this.abcTableAdapter.Fill(this.dataSet1.abc);

And I created DataGridViewComboBoxColumn called AllGrades:

DataGridViewComboBoxColumn AllGrades = new DataGridViewComboBoxColumn();            
        for (int grade = 5; grade <= 10; grade++)
        {
            AllGrades.Items.Add(grade);
        }
        AllGrades.DataPropertyName = "Grade";
        AllGrades.HeaderText = "Grade";
        AllGrades.Width = 60;
        AllGrades.MaxDropDownItems = 6;
        AllGrades.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
        dataGridView1.Columns.Add(AllGrades);

In a dataGridView I have a column Grades, which is connected to a database. I have created this code above in a case, if its needed to repair the grade. Thats why I decided to use a dropDown menu. The code above shows in a dropDown menu grades from 5 to 10.
I did aditional button Save, which will save the new selected value into db. But I am struggling to create additional code for inserting the new selected grade back into database.
Can someone help me out how to do it?

Mitja Bonca 557 Nearly a Posting Maven

How to do comparions (or equalizations) in a Query builder (for a dataGridView)?
I mean, I would like to select Grade and a Teacher who gave this grade, but I need to do a comparison to two listBox. In 1st I select a Student and in 2nd I select a Teacher. I know how to do in a normal query with select statement, but I dont know how to do it in a automatic query builder!