Click here to Skip to main content
15,892,927 members
Home / Discussions / Database
   

Database

 
GeneralRe: stumped Pin
Rocky Moore19-Aug-03 22:58
Rocky Moore19-Aug-03 22:58 
GeneralRe: stumped Pin
Shotgun20-Aug-03 1:44
Shotgun20-Aug-03 1:44 
GeneralHelp with sql trigger Pin
Ista19-Aug-03 11:32
Ista19-Aug-03 11:32 
GeneralRe: Help with sql trigger Pin
Jason McBurney21-Aug-03 4:54
Jason McBurney21-Aug-03 4:54 
GeneralRe: Help with sql trigger Pin
Ista21-Aug-03 4:56
Ista21-Aug-03 4:56 
GeneralRe: Help with sql trigger Pin
Mike Dimmick22-Aug-03 4:04
Mike Dimmick22-Aug-03 4:04 
GeneralRe: Help with sql trigger Pin
Ista22-Aug-03 4:11
Ista22-Aug-03 4:11 
QuestionHELP!!! why it's so hard to insert a row to Database by ADO.NET? Pin
yyf19-Aug-03 9:20
yyf19-Aug-03 9:20 
Confused | :confused: HELP!!!

I am trying to insert a row into an Access table using ADO.Net & C#. But it always give me an exception of "Syntax Error". But I don't understand, I am using the OleDbCommandBuilder to build the sql, why it has syntax error?
Please help me, I am almost crazy!!!!

Here is the table I want to insert records:
table name : Table1
fields:
ID: int, (AutoNumber, primary key)
SaveDate: Date/Time, default value = CDate() // this field is used to save the date&time when this row insert, so I don't want to write it in my code
field1: text(20)
field2: text(20)
field3: text(30)


Here is my code:

public bool Insert()<br />
{<br />
	try<br />
	{<br />
		OleDbDataAdapter da = new OleDbDataAdapter(<br />
			"select top 1 * from table1", <br />
			"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\test.mdb;User Id=;Password=;Mode=ReadWrite");<br />
<br />
		DataSet ds = new DataSet();<br />
		da.Fill(ds, "table1");<br />
		OleDbCommandBuilder bld = new OleDbCommandBuilder(da);<br />
<br />
		DataRow r = ds.Tables[0].NewRow();<br />
		for ( int i = 0; Table1[i].Field != null; i++ ) <br />
		{<br />
	   	    if ( string.Compare(Table1[i].Field, "ID", true) != 0 &&<br />
		    string.Compare(Table1[i].Field, "SaveDate", true) != 0 )   <br />
	     	    { <br />
		        r[Table1[i].Field] = Table1[i].Value;<br />
		    }<br />
		}<br />
		ds.Tables[0].Rows.Add(r);<br />
		int naffected = da.Update(ds, "table1");<br />
		da.Dispose();<br />
		da = null;<br />
		if ( naffected > 0 )<br />
			return true;<br />
	} <br />
	catch ( Exception e ) <br />
	{<br />
		ShowMessage(e.Message);<br />
	}<br />
	return false;<br />
}

AnswerRe: HELP!!! why it's so hard to insert a row to Database by ADO.NET? Pin
yyf19-Aug-03 10:25
yyf19-Aug-03 10:25 
GeneralRe: HELP!!! why it's so hard to insert a row to Database by ADO.NET? Pin
Tom Archer25-Aug-03 15:42
Tom Archer25-Aug-03 15:42 
Generalhelp with common ASP/SQL speed issues Pin
kaht19-Aug-03 7:20
kaht19-Aug-03 7:20 
GeneralRe: help with common ASP/SQL speed issues Pin
Jason McBurney21-Aug-03 4:57
Jason McBurney21-Aug-03 4:57 
GeneralRe: help with common ASP/SQL speed issues Pin
Mike Dimmick22-Aug-03 5:04
Mike Dimmick22-Aug-03 5:04 
GeneralRe: help with common ASP/SQL speed issues Pin
kaht25-Aug-03 3:03
kaht25-Aug-03 3:03 
GeneralJet OLEDB:Format Pin
Anthony988719-Aug-03 5:52
Anthony988719-Aug-03 5:52 
QuestionHow to make smaller ACCESS initial file ? Pin
vgrigor19-Aug-03 4:15
vgrigor19-Aug-03 4:15 
GeneralTransactions with Access Pin
Jerome Conus19-Aug-03 2:43
Jerome Conus19-Aug-03 2:43 
GeneralRe: Transactions with Access Pin
RichardGrimmer19-Aug-03 5:21
RichardGrimmer19-Aug-03 5:21 
GeneralRe: Transactions with Access Pin
Steve S19-Aug-03 22:15
Steve S19-Aug-03 22:15 
GeneralMacro to update data from excel file Pin
PrasadD18-Aug-03 14:07
PrasadD18-Aug-03 14:07 
GeneralRe: Macro to update data from excel file Pin
xoph21-Aug-03 1:33
xoph21-Aug-03 1:33 
QuestionToo Complex For Me...Maybe You? Pin
jesus4u18-Aug-03 8:03
jesus4u18-Aug-03 8:03 
AnswerRe: Too Complex For Me...Maybe You? Pin
basementman18-Aug-03 10:00
basementman18-Aug-03 10:00 
GeneralRe: Too Complex For Me...Maybe You? Pin
jesus4u18-Aug-03 10:04
jesus4u18-Aug-03 10:04 
GeneralRe: Too Complex For Me...Maybe You? Pin
basementman18-Aug-03 10:08
basementman18-Aug-03 10:08 

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.