C# .NET - error in the code
Asked By Dvorkin
05-Sep-10 01:36 PM
i write the following code and adding data in the text box through combo box which is linked with access database but it is giving error .... the error is (Object is not an ADODB.RecordSet or an ADODB.Record.Parameter name: adodb)
... can you tell me what is the error in the following code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Harpreet\\Documents\\access\\db2.mdb");
OleDbCommand cmdd = new OleDbCommand("Select * from Table1 where name ='" + comboBox1.SelectedValue + "'", con);
OleDbDataAdapter adpp = new OleDbDataAdapter(cmdd);
DataTable dtr = new DataTable();
adpp.Fill(dtr, "Table1");
if (dtr.Rows.Count > 0)
{
textBox1.Text = dtr.Rows[0]["Table1"].ToString();
}
}
Web Star replied to Dvorkin
see this link , it has solution for that.
http://www.vbforums.com/archive/index.php/t-425414.html
Access Database) Getting error input string not in correct format private void button4_Click(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = | DataDirectory | \ AddressBook.accdb"); con.Open(); int i i+", '"+textBox2.Text+"', '"+textBox3.Text+"', '"+textBox4.Text+"', '"+textBox5.Text+"', '"+Convert.ToInt32(textBox6.Text)+"', '"+textBox7.Text+"')"; OleDbCommand cmd = new OleDbCommand(queryinsert, con); cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); } Here is the modified code, You need value i to string while appending it to the string. private void button4_Click(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = | DataDirectory | \ AddressBook.accdb"); con.Open(); int i
public partial class Form1 : Form { public Form1() { InitializeComponent(); } string fname; private void button1_Click(object sender, EventArgs e) { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; long Lastrow namespace CompareExcel { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void BtnBrws1_Click(object sender, EventArgs e) { OpenFileDialog DialogA = new OpenFileDialog(); DialogA.CheckFileExists = true; / / DialogA.InitialDirectory = "Desktop" DialogA.Title = "Select a else if(FileTxt1.Text = = "") { MessageBox.Show("Please Select a File"); } } private void BtnBrws2_Click(object sender, EventArgs e) { OpenFileDialog DialogB = new OpenFileDialog(); DialogB.CheckFileExists = true; DialogB.Title = "Select a file"; if (DialogB else if(FileTxt2.Text = = "") { MessageBox.Show("Please Select a File"); } } private void BtnCmpr_Click(object sender, EventArgs e) { string filename1 = FileTxt1.Text; string filename2 = FileTxt2.Text; / / MessageBox.Show(filename1); / / MessageBox.Show(filename2 filename2 + ";" + "Extended Properties = Excel 12.0;"; / / Create connection object by using the preceding connection string. OleDbConnection objConn = new OleDbConnection(sConnectionString1); / / Open connection with the database. objConn.Open(); / / The code to follow uses a SQL SELECT command to display the data from the worksheet. / / Create new OleDbCommand to return data from worksheet OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + file1_sheet + "$]", objConn); / / Create new OleDbDataAdapter that is used to build
Text;HDR = YES;FMT = Delimited \ ";" , "" , "" , 0); string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]" ; ADODB.Recordset rs = new ADODB.Recordset(); System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(); DataTable dt = new DataTable(); rs.Open(strQuery, "Provider = Microsoft.Jet.OleDb.4.0; Data Source Data.OleDb; public partial class _Default : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Button1_Click( object sender, EventArgs e) { string target = Server.MapPath( "~ / Upload" ); if (FileUpload1.HasFile) { FileUpload1.SaveAs(System.IO.Path.Combine
Jet.OLEDB.4.0;Extended Properties = Text;Data Source = " & fi.DirectoryName Dim objConn As New OleDbConnection(sConnectionString) objConn. Open () Dim objCmdSelect As New OleDbCommand( "SELECT * FROM " & fi.Name, objConn) Dim objAdapter1 As New OleDbDataAdapter objAdapter1.SelectCommand = objCmdSelect Dim objDataset1 As New DataSet objAdapter1.Fill(objDataset1, "test" ) DataGridView1.DataSource = objDataset1 Text;HDR = YES;FMT = Delimited \ ";" , "" , "" , 0); string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]" ; ADODB.Recordset rs = new ADODB.Recordset(); System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(); DataTable dt = new DataTable(); rs.Open(strQuery, "Provider = Microsoft
and contact no. . .can anyone give me the code private void ReadExcelFile_Load( object sender, System.EventArgs e) { string File_name = null ; File_name = "C: \ ExcelFileTest.xls" ; / / dataGrid1.DataSource = GetDataFromExcelFile(Application.StartupPath + " \ ExcelFileTest.xls strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = " + File_name + "; Extended Properties = Excel 8.0;" ; OleDbConnection ObjConn = new OleDbConnection(strConn); ObjConn.Open(); / / Creación de Objeto listo para tomar datos OleDbCommand ObjCmd = new OleDbCommand( "SELECT * FROM [ExcelFileTest$]" , ObjConn); OleDbDataAdapter objDA = new OleDbDataAdapter(); objDA.SelectCommand = ObjCmd; / / Llenado de DataSet DataSet ObjDataSet = new DataSet(); objDA.Fill(ObjDataSet); / / Limpieza y rows & columns) of staff sheet as below, Dim cn as ADODB.Connection Dim oRS as ADODB.RecordSet Set cn = New ADODB.Connection set oRS = new ADODB.RecordSet With cn .Provider = "Microsoft