|
thx,
still left with a prob
see modified
|
|
|
|
|
i have used the update before in this project and i dont have errors there,
i thought that if my adapter wasn't set up properly the update wouldn't work anywere.
i use it to add a row, and this works perfect
|
|
|
|
|
what type is tabel1TableAdapter (I have not done database access this way before so i am stepping on new ground).
Is the row in the table related to any other tables which is causing some type of constrain error?
|
|
|
|
|
adding a row does not mean that deleting and modifying work as well. have a read for the setup. it also would be nice to know which kind of data adapter you are using.
there are several types that's why posting the line where the tableadapter is defined would be nice.
|
|
|
|
|
no, the adapter is linkt to only 1 table,
i get the error here, after i deleted it form the datagrid with the delet() funtion:
// apply delete to the database
try
{
tabel1TableAdapter.Update(db1DataSet.tabel1);//here i get the error
db1DataSet.AcceptChanges();
// refresh after the delete
this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1);
Application.DoEvents();
}
catch (System.Exception ex)
{
db1DataSet.RejectChanges();
lbl_error.Text= ex.Message;
}
if i switch tabel1..... and db1dataSet from place, i dont get it but then it doesnt change in the database
thx
|
|
|
|
|
tabel1TableAdapter.Connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\user\Desktop\test\prog\database2005\access\" + i + ".mdb";
and string i = "day" + DateTime.Now.DayOfYear.ToString();
|
|
|
|
|
okay, this is still not an answer to my question but i assume you're using a OleDbDataAdapter... use the link i posted some comments before - if it doesn't work for you write down the problems you're expiriencing.
good luck,
mik
|
|
|
|
|
sorry,
i'm not using oledbdataadapter, i used the wizard by using the data in the toolbar
i know now that i need to make a deletecommand but i'm not sure how,
?=tabel1TableAdapter.Connection.CreateCommand();
what do i use here to get a deletecommand?
i cant find it anywere
thx for the help
|
|
|
|
|
i used the update to add a row as wel and here it works perfect
so i dont think its caused by my settings of the dataadapter
|
|
|
|
|
That simply means that your dataAdapter is succesfully linking to the database. Your problem lies with the delete command inside the Update function.
Did you write these yourself or did you use the IDE (VS2003 etc)?
Can you also embed the actual error result into the message as they are usually quite explicit. You will need to higlight the error message text with your mouse and then use Ctrl-C and Ctrl-V.
Glen Harvy
|
|
|
|
|
i used the wizard apply in from the toolbar datagrid vs2005
so how do i make a deletecommand than?
i know how to do it with oledb but i dont use that,
i foud the way to create command but not to specify it as a delete command
?=tabel1TableAdapter.Connection.CreateCommand();
do i use the dbDataSet of what?
i am realy confused
and were do i write this? together with the connectionstring?
this is the error i am getting now :
Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.
thx
|
|
|
|
|
faladrim wrote: i used the wizard apply in from the toolbar datagrid vs2005
OK - It's quite posible that when you clicked "Finish" when you created the datatable, VS2005 didn't create all the commands - including the delete command. Open your ????DataSet.xsd file and highlight the datatable that is giving you problems. Right click it and select Configure. Go thru each step till the end and make sure the wizard has generated all the commands for you - there are 8 of them including the delete command. If it hasn't then you have either not configured the SELECT command properly (it's the command that the wizard uses to base it's generation of the other commands)or the tableadapter is having problems with the database's table itself.
The following snippet of code may also help:
<br />
for (int i = 0; i < foundRows.Length; i++)<br />
{<br />
foundRows[i].Delete();<br />
}<br />
this.meetingsAttendanceTableAdapter.Update(this.myclubDataSet.MeetingsAttendance);<br />
this.myclubDataSet.AcceptChanges();<br />
Let me know how you go
Glen Harvy
|
|
|
|
|
lo,
i inserted a deletecommand with commandtext DELETE FROM tabel1, but if i select a row in my program and press the delete button, everything is deleted; is there something wrong in my code?
i thought that i specifed the nummer of the row and that this one was deleted.
DataRow selectedrow = db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index ];
selectedrow.Delete();
// apply delete to the database
try
{
tabel1TableAdapter.Update(db1DataSet.tabel1);
db1DataSet.AcceptChanges();
// refresh after the delete
this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1);
Application.DoEvents();
}
catch (System.Exception ex)
{
db1DataSet.RejectChanges();
lbl_error.Text= ex.Message;
}
-- modified at 5:04 Monday 18th September, 2006
|
|
|
|
|
faladrim wrote: i inserted a deletecommand with commandtext DELETE FROM tabel1, but if i select a row in my program and press the delete button, everything is deleted; is there something wrong in my code?
I assume that you have NOT created an oldedb/sql command to delete anything and that the only code in your file that relates to this is the code you have quoted.
I presume that the "on_click" for the button has no other code besides the code you have quoted.
I would change your code as follows:
<br />
try<br />
{<br />
DataRow selectedrow = db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index ]; <br />
selectedrow.Delete();<br />
tabel1TableAdapter.Update(db1DataSet.tabel1);<br />
db1DataSet.AcceptChanges();<br />
this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1);<br />
}<br />
catch (System.Exception ex)<br />
{<br />
db1DataSet.RejectChanges();<br />
lbl_error.Text= ex.Message;<br />
}<br />
I think any problems with any of your code will now be revealed.
Let me know how you go.
Glen Harvy
|
|
|
|
|
faladrim wrote: i inserted a deletecommand with commandtext DELETE FROM tabel1,
I assume that you have NOT created an oldedb/sql command to delete anything and that the only code in your file that relates to this problem is the code you have quoted.
I presume that the "on_click" for the button has no other code besides the code you have quoted.
I would change your code as follows:
// apply delete to the database
try
{
DataRow selectedrow = db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index ];
selectedrow.Delete();
tabel1TableAdapter.Update(db1DataSet.tabel1);
db1DataSet.AcceptChanges();
// refresh after the delete
this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1);
}
catch (System.Exception ex)
{
db1DataSet.RejectChanges();
lbl_error.Text= ex.Message;
}
I think any problems with any of your code will now be revealed. If you have any problems please quote the whole error message you get.
Let me know how you go.
Glen Harvy
Glen Harvy
|
|
|
|
|
lo,
i have no error messages at all,
but my whole table is deleted and not the one i selected
so i thought it was because of the datarow selectedrow.... code line
i changed it to db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index].Delete();
witch does the same
so i still get an emty grid after wiching to delete just one
i am pretty sure that my commandtext is wrong,
heres what i did:
i opened the db1Dataset.xsd
looked into the property screen right-below and changed deletecommand from none to new
and entered in the commandtext: delete from tabel1
thx for the help
grz
|
|
|
|
|
The problem is in the tableAdapter.
Go back into the db1DataSet.xsd and delete the adapter.
Use the wizard and let it create ALL the commands - basically just accept the defaults as you go thru the wizard. There should only be a FillBy in the properties and nothing else - the other commands are "hidden".
There is no need for you to manually create any of the update, delete etc commands.
Then try running your program again.
Glen Harvy
|
|
|
|
|
then i get the error i started with cause there is no delete command
this is what i just did cause there most be something going wrong:
i sleceted everything in dataset.xsd en deleted it
right click add tableadapter
wizard new connection and choose my connection = access database and his folder -> next
the only thing that i can highlight is use sql statements -> next
query bluilder choose my table, Select tabel1.* from tabel1, -> ok and -> next
3 things highlighted: fill datatable method name = fill, return a datatable method name = getdata, create method... and no method name -> next
configure succesful, and a list of the generated items :
SELECT, INSERT, table mappings, FILL, GET, UPDATE ->finish
so i dont have delete
what did i do wrong?
grz
|
|
|
|
|
Well - you have now found the location of your problem .
I have had the same situation before and found the problem was in my SELECT statement.
Highlight the dataTable and run the Configure wizard again. When you get to the actual place where you insert the SELECT Statement click on the Advanced button and make sure both options are ticked.
Change the statement to SELECT * FROM TABLE1.
Open the Query Builder and run Execute Query to make sure it works.
Continue with the wizard.
If the Delete Command still doesn't appear at the end of the Wizard BUT the Query worked OK when you ran it above then click REBUILD on your project. Close the project and then re-open it. Go through all the above again.
Be mindfull of your select statement and how it's worded. For example, Date fields need to be enclosed in [ ]. A DELETE statement (it's not a command by the way) can only be generated if the Database and the Select statement are designed to allow it to be created by the wizard.
There are quite a few bugs in VS2005 which I've found over the past 3 months and whilst the closing and reopening of VS2005 (not just the project) doesn't make sense it has fixed some of my problems.
Glen Harvy
|
|
|
|
|
stil the same problem
is it possible in access to make sure u cant delete? i didnt think so
|
|
|
|
|
lo, i have made it work by entering the next text in the commandtext:
delete from tabel1 where name = ? or address= ?
name and address are my collums, but this is not the answer, because in the futur the user of the programs is able to add a collum but with this he cant delete a row
something to think about hé
grz
|
|
|
|
|
This is where you are confused or you are confusing us:
There are two ways of manipulating your table in the database. One is in a connected state and the other is in a disconnected state.
A connected state is where you open your connection, run a command, and close your connection. Forget about rows and datgrids and IDE wizards, you are directly changing the table just the same as if you were using MS Access etc. It's here that you create your commands and why your latest attempt works.
A disconnected state is where you use a dataAdapter which connects to the database and loads the table into RAM. You then use the bindingsource (rows.delete etc) statements to manipulate the data in RAM. When you are finished playing around you call the adapter to "update" or transfer all the changes you have made in RAM back to the table in the database. The commands contained in the dataAdapter are hidden from you because you never need to amend or change them.
From what you are saying then it appears you are using BOTH methods and trying to mix them at the same time.
Glen Harvy
|
|
|
|
|
aha now i see the differt,
but that doesnt change why i cant use the disconnected state allone
|
|
|
|
|
The question is - why isn't the wizard creating the Delete statement.
I need to think about it and will get back to you if I can come up with some suggestions. It's 10:00 pm here so I might not get back to you tonight
Now you know where the problem is though, I suggest you now post another Message and see if there is anyone else out there that can help you with an answer.
Glen Harvy
|
|
|
|
|
In my application there are four pages (Page1, Page2, Page3 and Page4). Each page have some basic controls and Web grids and also a “Save” button.
If I click on a “Save” button from any page all four pages data is saved to Database. Please give me guidance / suggestions how I can solve this. If you send a sample code its great. I am using Asp.net 2.0, C# and Sql Server 2005.
thank u
pradeep varma m
|
|
|
|