473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

access database

69 New Member
hallo everyone,

Iam using access database and visual c# 2008. Iam tried to insert data into table with lot of method but nothing works, i dont know what is wrong. here is my codes
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             //txt1 = textBox1.Text;
  4.             //txt2 = textBox2.Text;
  5.             //String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";
  6.             //OleDbConnection cnJetDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb");
  7.             //cnJetDB.Open();
  8.  
  9.             CreateCustomerAdapter();
  10.            // cnJetDB.Open();
  11.            // OleDbDataAdapter oleDa = new OleDbDataAdapter();
  12.            // OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl)"+"VALUES (?,?,?,?)",cnJetDB);
  13.            //// cmdInsert.CommandText = "INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl)"+"VALUES (?,?,?,?)";
  14.            //     //"INSERT INTO userinfo (Username,Pwd,Openid,ServerUrl) VALUES (?,?,?,?)";
  15.            //// cmdInsert.Connection = cnJetDB;
  16.            // //cmdInsert.Parameters.Add(new OleDbParameter("Username", OleDbType.VarChar, 40, textBox1.Text));
  17.            // //cmdInsert.Parameters.Add(new OleDbParameter("Pwd", OleDbType.VarChar, 40, textBox2.Text));
  18.            // //cmdInsert.Parameters.Add(new OleDbParameter("Openid",OleDbType.VarChar,40,null));
  19.            // //cmdInsert.Parameters.Add(new OleDbParameter("ServerUrl",OleDbType.VarChar,40,null));
  20.            // cmdInsert.Parameters.Add(textBox1.Text, OleDbType.VarChar, 40, "Username");
  21.            // cmdInsert.Parameters.Add(textBox2.Text, OleDbType.VarChar, 40, "Pwd");
  22.            // cmdInsert.Parameters.Add("null", OleDbType.VarChar, 40, "Openid");
  23.            // cmdInsert.Parameters.Add("null", OleDbType.VarChar, 40, "ServerUrl");
  24.  
  25.            // oleDa.InsertCommand = cmdInsert;
  26.            // //DataTable dtTest = new DataTable();
  27.            // //oleDa.Fill(dtTest);
  28.            // cmdInsert = null;
  29.            //  cnJetDB.Close();
  30.            //  cnJetDB = null;
  31.  
  32.  
  33.  
  34.              //using (OleDbConnection connection = new OleDbConnection(connectionString))
  35.              //{
  36.              //    OleDbCommand command = new OleDbCommand();
  37.              //    command.CommandType = CommandType.TableDirect;
  38.              //    command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  39.              //    command.Connection = connection;
  40.  
  41.              //    connection.Open();
  42.              //    OleDbDataReader reader = command.ExecuteReader();
  43.  
  44.  
  45.              //    reader.Close();
  46.              //    connection.Close();
  47.  
  48.              //}
  49.  
  50.            // OleDbConnection connection = new OleDbConnection(connectionString);
  51.            // OleDbDataAdapter adapter = new OleDbDataAdapter();
  52.  
  53.  
  54.            // OleDbCommand command = new OleDbCommand();
  55.            // // Create the InsertCommand.
  56.  
  57.            // command.CommandType = CommandType.Text;
  58.            // command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  59.  
  60.            // command.Connection = connection;
  61.            // //command.Parameters.Add("txt1", OleDbType.Char, 5, "Username");
  62.            // //command.Parameters.Add("txt2", OleDbType.VarChar, 10, "Pwd");
  63.  
  64.            //// adapter.InsertCommand = command;
  65.  
  66.            // connection.Open();
  67.  
  68.            // command.ExecuteNonQuery();
  69.            // connection.Close();
  70.  
  71.             //txt1 = textBox1.Text;
  72.             //txt2 = textBox2.Text;
  73.             login.ActiveForm.Visible = false;
  74.             _form.Show();
  75.             _form.newop();
  76.  
  77.         }
  78.         private static OleDbDataAdapter CreateCustomerAdapter()
  79.         {
  80.             OleDbConnection cnJetDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Userinfo.accdb");
  81.             cnJetDB.Open();
  82.             OleDbDataAdapter oleDa = new OleDbDataAdapter();
  83.             OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl)" + "VALUES (?,?,?,?)", cnJetDB);
  84.  
  85.             cmdInsert.Parameters.Add("txt", OleDbType.VarChar, 40, "Username");
  86.             cmdInsert.Parameters.Add("Text", OleDbType.VarChar, 40, "Pwd");
  87.             cmdInsert.Parameters.Add("null", OleDbType.VarChar, 40, "Openid");
  88.             cmdInsert.Parameters.Add("null", OleDbType.VarChar, 40, "ServerUrl");
  89.  
  90.             oleDa.InsertCommand = cmdInsert;
  91.             //DataTable dtTest = new DataTable();
  92.             //oleDa.Fill(dtTest);
  93.             cmdInsert = null;
  94.             cnJetDB.Close();
  95.             cnJetDB = null;
  96.             return oleDa;
  97.         }
  98.  
The above code has all the method i have tried. sorry if there is lot of code in there. The lines which are commented are the one which i have tried. First time when i tried to insert i open the access it gave me an popup "certain content in the database has been disabled", even when i enable that content and enable macro no use.Any help is highly appreciable. struggling with this small problem for 2 days.

Thank you.

regards,
Dinesh.
Nov 19 '08 #1
4 1808
r035198x
13,262 MVP
Under HowTos, go to Browse all HowTos and check the .NET HowTos. You should find two articles called "How to use a database in your program".
Nov 19 '08 #2
sarabonn
69 New Member
Under HowTos, go to Browse all HowTos and check the .NET HowTos. You should find two articles called "How to use a database in your program".

yes admin, i already looked at it but nothing other than what i have used.

Thank you.
Nov 19 '08 #3
r035198x
13,262 MVP
Your current uncommented code doesn't have the execute part so statements are issued to the database.
Nov 19 '08 #4
sarabonn
69 New Member
Your current uncommented code doesn't have the execute part so statements are issued to the database.
hallo admin,

Thank you for your reply. I have used the cmdInsert.ExecuteNonQuery() but it gives me a error "Parameter ?_1 has no default value." in that line. Have any idea?..

thank you.
Dinesh.
Nov 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
11
by: Rosco | last post by:
Does anyone have a good URL or info whre Oracle and Access are compared to one another in performance, security, cost etc. Before you jump on me I know Oracle is a Cadillac compared to Access the...
64
by: John | last post by:
Hi What future does access have after the release of vs 2005/sql 2005? MS doesn't seem to have done anything major with access lately and presumably hoping that everyone migrates to vs/sql. ...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
49
by: Mell via AccessMonster.com | last post by:
I created databases on Access 2003 and I want to deploy them to users. My code was also done using 2003. If they have Ms Access 2000 or higher, will they be able to use these dbs with all code,...
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
34
by: Mathieu Trentesaux | last post by:
Hello I downloaded Office 2007 for this reason : It seems, once again, that it is impossible to save any modification done in a VBA library, from the main project in Access. The save button...
21
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and view records for others. I want to know a...
11
by: Harel | last post by:
I have a report SQL which have been working for a few weeks. Its large and the target database is large. It has 59 join, and I dont think there is anything I can do about this, since the DB I use...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.