Click here to Skip to main content
16,010,673 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 6:30
Shizam5-Dec-03 6:30 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 6:39
protectorHeath Stewart5-Dec-03 6:39 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 8:19
Shizam5-Dec-03 8:19 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 8:55
protectorHeath Stewart5-Dec-03 8:55 
GeneralRe: Trouble playing a sound Pin
Jerry Hammond5-Dec-03 16:20
Jerry Hammond5-Dec-03 16:20 
GeneralRe: Trouble playing a sound Pin
J. Dunlap5-Dec-03 9:17
J. Dunlap5-Dec-03 9:17 
GeneralIs it possible to disable the Messagebox/Dialog... Pin
Loke15-Dec-03 3:34
Loke15-Dec-03 3:34 
Questioninserting data into Access using C#?? Pin
Azel Low5-Dec-03 2:47
Azel Low5-Dec-03 2:47 
Hi,

I am trying to learn ADO.net using C# and I keep running into problems trying to insert data into my Access Database: data.mdb.

here is my code:

<br />
		// Database Variables<br />
		private string connectionStr = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""C:\data.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";<br />
		private string selectStr = "Select id, date, day, time, comments, timeout, status, process from data";<br />
<br />
		private System.Data.DataSet myDataSet;<br />
		private System.Data.OleDb.OleDbConnection myConnection;<br />
		private System.Data.OleDb.OleDbDataAdapter myDataAdapter;<br />
		private System.Data.OleDb.OleDbCommandBuilder myCmdBuilder;<br />
		<br />
		private System.Data.OleDb.OleDbCommand mySelectCmd;<br />
<br />
		public Schedule()<br />
		{          <br />
			this.InitilizeDb();<br />
			this.PopulateDataSet();<br />
		}<br />
<br />
		private OleDbConnection ConnectDb()<br />
		{<br />
			return new OleDbConnection(connectionStr);<br />
		}<br />
<br />
		public void InitilizeDb()<br />
		{<br />
			myDataAdapter = new OleDbDataAdapter();<br />
			myCmdBuilder = new OleDbCommandBuilder(myDataAdapter);<br />
			myDataSet = new DataSet();<br />
		}<br />
<br />
		private void PopulateDataSet()<br />
		{<br />
			// get the connection object<br />
			myConnection = (OleDbConnection) this.ConnectDb();<br />
<br />
			// Initilize the Select Command<br />
			mySelectCmd = new OleDbCommand(selectStr, myConnection);<br />
<br />
			// Define that the Select Command is an SQL statement<br />
			mySelectCmd.CommandType = CommandType.Text;<br />
<br />
			try<br />
			{<br />
				myConnection.Open();<br />
<br />
				myDataAdapter.SelectCommand = mySelectCmd;<br />
<br />
				// Populate the DataSet from the "data" table<br />
				myDataAdapter.Fill(myDataSet,"data");<br />
			}<br />
			finally<br />
			{<br />
				myConnection.Close();<br />
			}<br />
		}<br />
<br />
		public string InsertSchedule(string date, string day, string time, string process,<br />
			string comments, string timeout, string status)<br />
		{<br />
			// get the connection object<br />
			myConnection = (OleDbConnection) this.ConnectDb();<br />
<br />
			try<br />
			{<br />
				myConnection.Open();<br />
<br />
				// create a new row to insert the data into<br />
				DataRow newRow = myDataSet.Tables["data"].NewRow();<br />
<br />
				// initilize the new row<br />
				newRow["id"] = 3;<br />
				newRow["date"] = date;<br />
				newRow["day"] = day;<br />
				newRow["time"] = time;<br />
				newRow["process"] = process;<br />
				newRow["comments"] = comments;<br />
				newRow["timeout"] = timeout;<br />
				newRow["status"] = status;<br />
<br />
				// add the new row into the dataset<br />
				myDataSet.Tables["data"].Rows.Add(newRow);<br />
<br />
				myDataAdapter.Update(myDataSet, "data");<br />
<br />
				return "true";<br />
			}<br />
			catch(Exception e)<br />
			{<br />
				return e.Message + "\n\n" + e.StackTrace + "\n\n" + e.InnerException;<br />
			}<br />
			finally<br />
			{<br />
				myConnection.Close();<br />
			}<br />
		}<br />


the problem is when I try to insert into the database, I keep getting this Exception:

Syntax error in INSERT INTO statement.<br />
<br />
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)<br />
   at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)<br />
   at ShutdownMgr.Schedule.InsertSchedule(String date, String day, String time, String process, String comments, String timeout, String status) in c:\documents and settings\azel\my documents\visual studio projects\shutdownmgr\schedule.cs:line 99<br />


I have tried different ways but none were successful. Is anyone able to spot where I am going wrong? Dead | X|

thanks.
AnswerRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 4:04
protectorHeath Stewart5-Dec-03 4:04 
GeneralRe: inserting data into Access using C#?? Pin
Azel Low5-Dec-03 4:10
Azel Low5-Dec-03 4:10 
GeneralRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 4:32
protectorHeath Stewart5-Dec-03 4:32 
GeneralRe: inserting data into Access using C#?? Pin
Azel Low5-Dec-03 4:41
Azel Low5-Dec-03 4:41 
GeneralRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 4:46
protectorHeath Stewart5-Dec-03 4:46 
GeneralRe: inserting data into Access using C#?? Pin
Azel Low5-Dec-03 4:53
Azel Low5-Dec-03 4:53 
GeneralRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 5:21
protectorHeath Stewart5-Dec-03 5:21 
GeneralRe: inserting data into Access using C#?? Pin
Jerry Hammond5-Dec-03 5:39
Jerry Hammond5-Dec-03 5:39 
GeneralRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 6:08
protectorHeath Stewart5-Dec-03 6:08 
GeneralRe: inserting data into Access using C#?? Pin
Jerry Hammond5-Dec-03 16:16
Jerry Hammond5-Dec-03 16:16 
QuestionWhat is the best way for Return Messages? Exceptions, return strings, return classes? Pin
gokselm5-Dec-03 1:55
gokselm5-Dec-03 1:55 
AnswerRe: What is the best way for Return Messages? Exceptions, return strings, return classes? Pin
Paul Watson5-Dec-03 2:31
sitebuilderPaul Watson5-Dec-03 2:31 
GeneralRe: What is the best way for Return Messages? Exceptions, return strings, return classes? Pin
David Stone5-Dec-03 3:33
sitebuilderDavid Stone5-Dec-03 3:33 
GeneralRe: What is the best way for Return Messages? Exceptions, return strings, return classes? Pin
Heath Stewart5-Dec-03 4:01
protectorHeath Stewart5-Dec-03 4:01 
AnswerRe: What is the best way for Return Messages? Exceptions, return strings, return classes? Pin
Stephane Rodriguez.5-Dec-03 2:38
Stephane Rodriguez.5-Dec-03 2:38 
GeneralRe: What is the best way for Return Messages? Exceptions, return strings, return classes? Pin
David Stone5-Dec-03 3:32
sitebuilderDavid Stone5-Dec-03 3:32 
QuestionHow Can I get the MSN style Use C#??? Pin
lupa_84215-Dec-03 1:06
lupa_84215-Dec-03 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.