Hi to all...Hope everyone is grand.I am currently working on a project that is supposed to connect to a .mdb(access) file and than bring out the project names in to the first listbox (listbox1) than when you click one of the elements in listbox1 you would get the selected projects ip numbers which will be displayed in another listbox(listbox3).My problem is with my OleDbDataReader I think...because when I debugged my file step by step it gave an "No value give for one or more required parameters" error.I haven't figured out why since the db1.mdb (database) file was indeed full.I have posted the design part of the code.For the full source file please click here.I have used Microsoft Visiual Studio 2005 as my code compiler.Please help I am currently very stuck...Thanks in advance...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Odbc;
using System.Data.Common;
namespace WindowsApplication1
{
public partial class Browser1 : Form
{
string selectedfr;
public Browser1()
{
InitializeComponent();
}
private void Browser1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'db1DataSet1.Projects' table. You can move, or remove it, as needed.
this.projectsTableAdapter1.Fill(this.db1DataSet1.Projects);
// TODO: This line of code loads data into the 'db1DataSet.Projects' table. You can move, or remove it, as needed.
this.projectsTableAdapter.Fill(this.db1DataSet.Projects);
this.projectsTableAdapter1.FillBy1(this.db1DataSet1.Projects);
string selcting = listBox1.SelectedItem.ToString();
}
private void showing()
{
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("SELECT IP FROM Projects WHERE (CompanyName = " + selectedfr + " )", aConnection);
MessageBox.Show("" + selectedfr + "");
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
//Iterate throuth the database
while (aReader.Read())
{
listBox2.Items.Add(aReader.GetData(2).ToString());
}
//close the reader
aReader.Close();
//close the connection Its important.
aConnection.Close();
}
//Some usual exception handling
catch (OleDbException e)
{
MessageBox.Show("Error: {0} "+ e.Errors[0].Message);
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.projectsTableAdapter1.FillBy(this.db1DataSet1.Projects);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void fillBy1ToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.projectsTableAdapter1.FillBy1(this.db1DataSet1.Projects);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void fillBy1ToolStripButton_Click_1(object sender, EventArgs e)
{
try
{
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
}
private void button8_Click(object sender, EventArgs e)
{
this.Close();
}
public void listBox1_MouseClick(object sender, MouseEventArgs e)
{
selectedfr =listBox1.Text.ToString();
showing();
}
}
}