Jump to content
Xtreme .Net Talk

pendragon

Avatar/Signature
  • Posts

    214
  • Joined

  • Last visited

Everything posted by pendragon

  1. Hi All When you create a mail label report using Crystal Reports, you enter the label height, width, gaps between and margins. Does any one know if it is possible to change these once the label has been created, (did a typo and enter the wrong figures :rolleyes: ), or do I have to create the label again. Thanks
  2. Right click on a free part of the report, from menu go to designer and select printer setup. You can then select Portrait or Landscape there.
  3. Right click on the grey Report Footer Bar then select Format Section from the menu, choose the section you want to add the condition to, on the right there is a list of things you can do one being Suppress (No drill down), next to this is a button that allows you to put a condition in.
  4. Have you had a look at delegates, the following link might help http://www.xtremedotnettalk.com/showthread.php?t=87400
  5. Thank you for the reply Hog For some reason this does not work, I am begining to think this might be a bug in crystal reports. I am going to try and email them and see what they say.
  6. Hi I have a report that I am showing in the report viewer, I click the print button, get the print dialog box and select the printer I want. The problem I have is that the paper size is defaulting to the first paper size in the list (A4), the default for this printer is Letter Fanfold 8.5 x 11 which is the one I need. If I choose this printer in word it is fine and shows the correct paper size as default. Does anyone know why this is happening and how to fix it. Thanks in advance.
  7. I found an article by microsoft with this error and it says the following If you set a column size smaller than the data currently in the field, you receive the following message, and the data type change will not occur: In an Access database (.mdb): The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. Hope this helps
  8. Hi I have a usercontrol that asks for a date, in the control I have a Leave event defined that checks to see if a valid date has been entered and if not then show a message and go back to the control. I need to use this to enter a date and check to make sure it is in a date range, if not tell them it is invalid and ask the date again. I can do this by using the leave event in the new program. My problem is the order that it executes the two leave events, at the moment it does the one in the program and then the one in the user control, what I need is for it to check if it is a vaild date (the user control leave event) and then check to see if it is within the date range (the programs leave event) Can anyone tell me how to do this Thanks
  9. This is how I do it crReportDocument.Database.Tables[0].SetDataSource(your_datasource);
  10. Sorted This report queries several different databases and collates the data, one of them only I have access to at this time, because of this I get the error, give the MD access to the directory and it works fine. (Job safe for the moment :D ) Seems a strange error to give but it is running on a Novel network so maybe that is why.
  11. Not sure where to put this so will try here. I have a program that asks for a date and then creates a report from that date. It uses old style ADO and querys an Access database. On my machine all works ok but on the users machine it comes up will 'Out of MS-DOS File Handles', I have tried it on 3 machines and they all do the same. I don't get it, this is a windows forms program not an MS-DOS console program so why would I get this error. To make matters worse this is the only program that was written for the MD so if anyone can PLEASE give me a clue as to what this is I would be gratefull. Thanks
  12. I have now got a work around for this. The problem lies in the WHERE clause of the SQL statement, for some reason if I have SOPDueDate = ? then, when it is checking the original values, if it is DBNull it fails the comparison and never finds a record to update. As I have a procedure to make the update command from a data table that it receives as a parameter and all my table primary keys are the first fields on the table, I think I will change the WHERE clause to just be 'WHERE [tablePrimary] = ?', as there is only one record per key this will get over the problem, whether this is good programming practice I have no idea. If anyone out there has a clue as to why the comparison check is failing on the DBNull check then please let me know as I would like to know if I am doing something wrong. Thank you
  13. Thanks for the reply laredo512 I think there is something somewhere that I don't understand, inserting a new record with a null date is working ok, what I can't get to work is when I try to Update a record that started with a null date I get the message 'the update command affected 0 records' :confused:
  14. Well now I am back at work have managed to find out why my update command doesn't work. private void TestADO_Load(object sender, System.EventArgs e) { ds = new DataSet(); SQL = "SELECT SOPOrdNo, SOPAccID, SOPCustRef, SOPEntry, SOPProcess, SOPDate, SOPDelDate, SOPDueDate FROM SOPHeader ORDER BY SOPOrdNo"; cn = new OleDbConnection(dataaccess.SLConString); cn.Open(); Application.DoEvents(); da = new OleDbDataAdapter(SQL, cn); da.TableMappings.Add("Table", "SOPHeader"); tbl = ds.Tables.Add("SOPHeader"); col = tbl.Columns.Add("SOPOrdNo", typeof(int)); col.AutoIncrement = true; col.AutoIncrementSeed = -1; col.AutoIncrementStep = -1; col = tbl.Columns.Add("SOPAccID", typeof(string)); col.AllowDBNull = false; col.MaxLength = 16; col = tbl.Columns.Add("SOPCustRef", typeof(string)); col = tbl.Columns.Add("SOPEntry", typeof(string)); col = tbl.Columns.Add("SOPProcess", typeof(string)); col = tbl.Columns.Add("SOPDate", typeof(DateTime)); col.AllowDBNull = true; col = tbl.Columns.Add("SOPDelDate", typeof(DateTime)); col.AllowDBNull = true; col = tbl.Columns.Add("SOPDueDate", typeof(DateTime)); col.AllowDBNull = true; tbl.PrimaryKey = new DataColumn[] {tbl.Columns["SOPOrdNo"]}; dataaccess.tblSOPHeader = ds.Tables["SOPHeader"]; dataaccess.colSOPOrdNo = dataaccess.tblSOPHeader.Columns["SOPOrdNo"]; dataaccess.colSOPAccID = dataaccess.tblSOPHeader.Columns["SOPAccID"]; dataaccess.colSOPCustRef = dataaccess.tblSOPHeader.Columns["SOPCustRef"]; dataaccess.colSOPEntry = dataaccess.tblSOPHeader.Columns["SOPEntry"]; dataaccess.colSOPProcess = dataaccess.tblSOPHeader.Columns["SOPProcess"]; dataaccess.colSOPDate = dataaccess.tblSOPHeader.Columns["SOPDate"]; dataaccess.colSOPDelDate = dataaccess.tblSOPHeader.Columns["SOPDelDate"]; dataaccess.colSOPDueDate = dataaccess.tblSOPHeader.Columns["SOPDueDate"]; da.Fill(ds, "SOPHeader"); } [/Code] [code] string sql; cn = new OleDbConnection(dataaccess.SLConString); SQL = "SELECT * FROM SOPHeader ORDER BY SOPOrdNo"; da = new OleDbDataAdapter(SQL, cn); cn.Open(); OleDbCommand cmd; sql = "UPDATE [sOPHeader]"; sql += " SET SOPAccID = ?, SOPCustRef = ?, SOPEntry = ?, SOPProcess = ?, SOPDate = ?, SOPDelDate = ?, SOPDueDate = ?"; sql += " WHERE SOPOrdNo = ? AND SOPAccID = ? AND SOPCustRef = ? AND SOPEntry = ? AND SOPProcess = ? AND SOPDate = ? AND SOPDelDate = ? AND SOPDueDate = ?"; cmd = new OleDbCommand(sql, cn); //sql, cn); OleDbParameterCollection pc = cmd.Parameters; pc.Add("SOPAccID_new", OleDbType.Char, 0, "SOPAccID"); pc.Add("SOPCustRef_new", OleDbType.Char, 0, "SOPCustRef"); pc.Add("SOPEntry_new", OleDbType.Char, 0, "SOPEntry"); pc.Add("SOPProcess_new", OleDbType.Char, 0, "SOPProcess"); pc.Add("SOPDate_new", OleDbType.Date, 0, "SOPDate"); pc.Add("SOPDelDate_new", OleDbType.Date, 0, "SOPDelDate"); pc.Add("SOPDueDate_new", OleDbType.Date, 0, "SOPDueDate"); OleDbParameter param; param = pc.Add("SOPOrdNo_Orig", OleDbType.Char, 0, "SOPOrdNo"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPAccID_new", OleDbType.Char, 0, "SOPAccID"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPCustRef_new", OleDbType.Char, 0, "SOPCustRef"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPEntry_new", OleDbType.Char, 0, "SOPEntry"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPProcess_new", OleDbType.Char, 0, "SOPProcess"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPDate_new", OleDbType.Date, 0, "SOPDate"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPDelDate_new", OleDbType.Date, 0, "SOPDelDate"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("SOPDueDate_new", OleDbType.Date, 0, "SOPDueDate"); param.SourceVersion = DataRowVersion.Original; this.SalesOrders[dataaccess.colSOPEntry] = "Data"; this.SalesOrders[dataaccess.colSOPProcess] = "Adapter"; this.SalesOrders[dataaccess.colSOPDueDate] = DateTime.Parse("31/08/2004"); da.UpdateCommand = cmd; try { da.Update(ds, "SOPHeader"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } The problem is with SOPDueDate, I am importing a CSV file from the old system and this one did not have a Due Date. The import program was written using VB.Net and Old style ADO, the due date is set to DBNull.Value and then saved. Everything is fine in ADO.NET untill I try to save a record with a date that is null. How do I get around this. Thanks
  15. Taking out the extra connection definition did not solve the problem. I am importing the data from a csv file and I had a problem before with a text field that was new in the access database and I was not setting it to anything in the import, this caused the update command not to work and I had to set it to "" to get it working. Hopefully this is the same sort of problem so I think I will write a test program and build up the command bit by bit to see if it falls over on one of the fields :o
  16. Diesel Thanks for your comments. I have been learning VB.NET then C# from Books for about a year and have not had anyone to bounce questions, comments and Ideas against (except for this forum, which is very good :D ) so I doubt that I am doing everything in the best way yet, I have only been playing with ADO.NET for the passed month so am no where near an expert on it. You say I am creating to many adapters and connection objects, I have 9 databases with just over 100 tables, are you saying that I should just define cn and da once and then redefine them as I use them? The sales order program alone looks at a table for Order Header, Order Lines, Sales Accounts, Delivery Header, Delivery Lines and Sales Analysis these are all in the sales ledger databases but it also looks at Stock Parts and production from the stock databases and Route card file from the costings database so three different connection definitions. One of the books I have read (Can't remember if it was a VB.NET or C#.NET book) says that it is a good Idea to get into the habit of calling the dispose method to get rid of no longer needed objects instead of leaving it to the GC, one of the reasons given was that they can sometimes hang around for a long time. If I am doing things wrong then I would really appreciate being told and also how I should be doing it. As for your questions 1) No, the other table is for Quarantine Stock. 2) SOPOrdNo is an Auto Incrementing Access field, step is set to -1 so that any new orders that are added will not be given a tempory order number that already exists. 3) This is a typo dataaccess.UpdateRowCommand(dataaccess.tblSOPHeader, c); Should Read dataaccess.UpdateRowCommandNoUnlock(dataaccess.tblSOPHeader, c); Thanks to your first comment I have seen something in the UpdateRowCommandNoUnlock that Is wrong. cn = new OleDbConnection(ADOConnectionString); // THIS SHOULD NOT BE HERE cmd = new OleDbCommand(sql, cn); OleDbParameterCollection pc = cmd.Parameters; OleDbParameter param; I am suprised that I did not notice this before as I had a problem with @@IDENTITY not returning newly created auto numbers because I defined cn again half way down the routine that fetched it. I don't know if this will solve the problem but will take it out and let you know. (I am supposed to be on holiday next week but will pop in on Monday to find out as this has been bugging me for 3 days). Thanks.
  17. Hi All I have a strange problem, I have a routine for creating an update command based on the table I send it, If I update a record on one table all is OK if I try to update a record on another table I get the following error Concurrency Violation : The Update Command Affected 0 Records Is there any way to find out why no records where affected (I did check to make sure that there was a change to make) What I do is this (There is a lot of code but I am hoping that someone can see a problem that I can't) Setup table public static void OpenSalesOrders(int tableno, string ASCorDESC) { SQL = "SELECT * FROM SOPHeader ORDER BY SOPOrdNo " + ASCorDESC; cn = new OleDbConnection(dataaccess.SLConString); cn.Open(); da = new OleDbDataAdapter(SQL, cn); da.TableMappings.Add("Table", "SOPHeader"); Application.DoEvents(); tbl = ds.Tables.Add("SOPHeader"); col = tbl.Columns.Add("SOPOrdNo", typeof(int)); col.AutoIncrement = true; col.AutoIncrementSeed = -1; col.AutoIncrementStep = -1; col = tbl.Columns.Add("SOPAccID", typeof(string)); col.AllowDBNull = false; col.MaxLength = 16; col = tbl.Columns.Add("SOPCustRef", typeof(string)); col = tbl.Columns.Add("SOPEntry", typeof(string)); col = tbl.Columns.Add("SOPProcess", typeof(string)); col = tbl.Columns.Add("SOPDate", typeof(DateTime)); col.AllowDBNull = true; col = tbl.Columns.Add("SOPDelDate", typeof(DateTime)); col.AllowDBNull = true; col = tbl.Columns.Add("SOPDueDate", typeof(DateTime)); col.AllowDBNull = true; col = tbl.Columns.Add("SOPTotal", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPDiscPer", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPDiscAmt", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPNett", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPGross", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT1", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT2", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT3", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT4", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT5", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT6", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT7", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT8", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVAT9", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVATZ", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVATE", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPVATX", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPValInv", typeof(decimal)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPPOP", typeof(bool)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPDelAddKey", typeof(int)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPDelAddName", typeof(string)); col = tbl.Columns.Add("SOPDelAdd", typeof(string)); col = tbl.Columns.Add("SOPDelPostCode", typeof(string)); col = tbl.Columns.Add("SOPNar1", typeof(string)); col = tbl.Columns.Add("SOPNar2", typeof(string)); col = tbl.Columns.Add("SOPProj", typeof(int)); col.DefaultValue = 0; col = tbl.Columns.Add("SOPTool", typeof(bool)); col.DefaultValue = false; col = tbl.Columns.Add("SOPPOPKey", typeof(int)); col = tbl.Columns.Add("SOPInvoice", typeof(bool)); col = tbl.Columns.Add("Locked", typeof(bool)); col = tbl.Columns.Add("LockedBy", typeof(string)); col = tbl.Columns.Add("LineCount", typeof(int)); col.AutoIncrement = true; col.AutoIncrementSeed = 0; col.AutoIncrementStep = 1; tbl.PrimaryKey = new DataColumn[] {tbl.Columns["SOPOrdNo"]}; tblSOPHeader = ds.Tables[tableno]; colSOPOrdNo = tblSOPHeader.Columns["SOPOrdNo"]; colSOPAccID = tblSOPHeader.Columns["SOPAccID"]; colSOPCustRef = tblSOPHeader.Columns["SOPCustRef"]; colSOPEntry = tblSOPHeader.Columns["SOPEntry"]; colSOPProcess = tblSOPHeader.Columns["SOPProcess"]; colSOPDate = tblSOPHeader.Columns["SOPDate"]; colSOPDelDate = tblSOPHeader.Columns["SOPDelDate"]; colSOPDueDate = tblSOPHeader.Columns["SOPDueDate"]; colSOPTotal = tblSOPHeader.Columns["SOPTotal"]; colSOPDiscPer = tblSOPHeader.Columns["SOPDiscPer"]; colSOPDiscAmt = tblSOPHeader.Columns["SOPDiscAmt"]; colSOPNett = tblSOPHeader.Columns["SOPNett"]; colSOPVAT = tblSOPHeader.Columns["SOPVAT"]; colSOPGross = tblSOPHeader.Columns["SOPGross"]; colSOPVAT1 = tblSOPHeader.Columns["SOPVAT1"]; colSOPVAT2 = tblSOPHeader.Columns["SOPVAT2"]; colSOPVAT3 = tblSOPHeader.Columns["SOPVAT3"]; colSOPVAT4 = tblSOPHeader.Columns["SOPVAT4"]; colSOPVAT5 = tblSOPHeader.Columns["SOPVAT5"]; colSOPVAT6 = tblSOPHeader.Columns["SOPVAT6"]; colSOPVAT7 = tblSOPHeader.Columns["SOPVAT7"]; colSOPVAT8 = tblSOPHeader.Columns["SOPVAT8"]; colSOPVAT9 = tblSOPHeader.Columns["SOPVAT9"]; colSOPVATZ = tblSOPHeader.Columns["SOPVATZ"]; colSOPVATE = tblSOPHeader.Columns["SOPVATE"]; colSOPVATX = tblSOPHeader.Columns["SOPVATX"]; colSOPValInv = tblSOPHeader.Columns["SOPValInv"]; colSOPPOP = tblSOPHeader.Columns["SOPPOP"]; colSOPDelAddKey = tblSOPHeader.Columns["SOPDELAddKey"]; colSOPDelAddName = tblSOPHeader.Columns["SOPDelAddName"]; colSOPDelAdd = tblSOPHeader.Columns["SOPDelAdd"]; colSOPDelPostCode = tblSOPHeader.Columns["SOPDelPostCode"]; colSOPNar1 = tblSOPHeader.Columns["SOPNar1"]; colSOPNar2 = tblSOPHeader.Columns["SOPNar2"]; colSOPProj = tblSOPHeader.Columns["SOPProj"]; colSOPTool = tblSOPHeader.Columns["SOPTool"]; colSOPPOPKey = tblSOPHeader.Columns["SOPPOPKey"]; colSOPInvoice = tblSOPHeader.Columns["SOPInvoice"]; colSOPLocked = tblSOPHeader.Columns["Locked"]; colSOPLockedBy = tblSOPHeader.Columns["LockedBy"]; colSOPLineCount = tblSOPHeader.Columns["LineCount"]; da.Fill(ds, "SOPHeader"); dataaccess.rcSOPHeader = (int)dataaccess.tblSOPHeader.Rows.Count - 1; da.Dispose(); tbl.Dispose(); col.Dispose(); cn.Close(); cn.Dispose(); Application.DoEvents(); } Change Something private void button4_Click(object sender, System.EventArgs e) { this.SOPHeader[dataaccess.colSOPNar1] += Environment.NewLine + "Has this Worked All Done in the Dataaccess class"; dataaccess.FormCallBack c = new Library.dataaccess.FormCallBack(ShowFields); dataaccess.UpdateRowCommand(dataaccess.tblSOPHeader, c); } Then Update public static void UpdateRowCommandNoUnlock(DataTable theTable) { string TableName = theTable.TableName; string sql = "UPDATE [" + TableName + "] SET "; OleDbCommand cmd = null; int totalrows = theTable.Columns.Count; bool started = false; SQLStatement = GetSQLStatement(TableName); cn = new OleDbConnection(ADOConnectionString); cn.Open(); dataaccess.da = new OleDbDataAdapter(dataaccess.SQLStatement, dataaccess.cn); for (int rowcount = 1; rowcount < totalrows; rowcount++) { if (theTable.Columns[rowcount].ColumnName != "LineCount") { if (started == false) { sql += theTable.Columns[rowcount].ColumnName + " = ?"; started = true; } else { sql += ", " + theTable.Columns[rowcount].ColumnName + " = ?"; } } } sql += " WHERE "; started = false; for (int rowcount = 0; rowcount < totalrows; rowcount++) { if (theTable.Columns[rowcount].ColumnName != "LineCount") { if (started == false) { sql += theTable.Columns[rowcount].ColumnName + " = ?"; started = true; } else { sql += " AND " + theTable.Columns[rowcount].ColumnName + " = ?"; } } } cn = new OleDbConnection(ADOConnectionString); cmd = new OleDbCommand(sql, cn); OleDbParameterCollection pc = cmd.Parameters; OleDbParameter param; for (int rowcount = 1; rowcount < totalrows; rowcount++) { if (theTable.Columns[rowcount].ColumnName != "LineCount") { RowDataType = GetDataType(theTable.Columns[rowcount].DataType); pc.Add(theTable.Columns[rowcount].ColumnName + "_New", RowDataType, 0, theTable.Columns[rowcount].ColumnName); } } for (int rowcount = 0; rowcount < totalrows; rowcount++) { if (theTable.Columns[rowcount].ColumnName != "LineCount") { RowDataType = GetDataType(theTable.Columns[rowcount].DataType); param = pc.Add(theTable.Columns[rowcount].ColumnName + "_Orig", RowDataType, 0, theTable.Columns[rowcount].ColumnName); param.SourceVersion = DataRowVersion.Original; } } da.UpdateCommand = cmd; try { da.Update(ds, TableName); ds.AcceptChanges(); } catch (DBConcurrencyException ex) { MessageBox.Show("Update Failed", ex.GetType().ToString()); MessageBox.Show(ex.ToString()); MessageBox.Show(ex.Message.ToString()); MessageBox.Show(ex.TargetSite.ToString()); MessageBox.Show(ex.Source.ToString()); } finally { cn.Dispose(); da.Dispose(); } } I have checked to see that the update command is correct and it is What am I doing wrong or how can I find out the why ????????????????? Thanks
  18. Thanks for that PlausiblyDamp it does exactly what I need :cool: I converted it to c# and it ended up slightly different to what you put in VB, in dataaccess class public delegate void FormCallBack(); . . . . public static void RefreshRecord(string row, FormCallBack CallBack) { MessageBox.Show(row); CallBack(); } Then in calling program private void button1_Click(object sender, System.EventArgs e) { dataaccess.FormCallBack c = new Library.dataaccess.FormCallBack(ShowFields); dataaccess.RefreshRecord("His is in the row", c); } private void ShowFields() { MessageBox.Show("This is from ShowFields"); } I think this is the way it should be done but if you can see something that can be done better then please let me know. I am going to have to read up on delegates to fully understand what can be done with them but this has given me a good start. :D Thanks
  19. Hi I have a class that I use for all my data access procedures, What I want to do is, when the user decides to amend the current record, the program will call a routine in my data access class that will re-fresh the row and then display it. The problem I have is as the routine will be called from lots of different forms I have no form name which means I can't program the form name at design time and I can't get at the forms routine to show the new data. Does anyone know of a way round this. thanks
  20. JABE I seem to always forget to use the try/catch block to get the exception, it told me exactly where the error was. Just for reference it was on this line sql += " WHERE STCPartID = ? AND STCDesc1 = ? STCDesc2 = ? "; Should off course look like this sql += " WHERE STCPartID = ? AND STCDesc1 = ? AND STCDesc2 = ? "; Thanks for that, now lets see what else I can break :D
  21. I am learning ADO.NET by reading Microsofts ADO.NET Core Reference, I understanding how to get data using the data adapter, how to fill a data set and how to use data rows to display and modify the data, but I can not get the data adapter to update the changed data to my database. I have created a small test program to try and figure this out, this is what I do in the Form Load Event. ds = new DataSet(); SQL = "SELECT STCPartID, STCDesc1, STCDesc2 FROM StockParts ORDER BY STCPartID"; cn = new OleDbConnection(dataaccess.STCConString); cn.Open(); Application.DoEvents(); da = new OleDbDataAdapter(SQL, cn); da.TableMappings.Add("Table", "StockParts"); tbl = ds.Tables.Add("StockParts"); col = tbl.Columns.Add("STCPartID", typeof(string)); col = tbl.Columns.Add("STCDesc1", typeof(string)); col = tbl.Columns.Add("STCDesc2", typeof(string)); tbl.PrimaryKey = new DataColumn[] {tbl.Columns["STCPartID"]}; dataaccess.tblSTCPart = ds.Tables["StockParts"]; dataaccess.colSTCPartID = dataaccess.tblSTCPart.Columns["STCPartID"]; dataaccess.colSTCDesc1 = dataaccess.tblSTCPart.Columns["STCDesc1"]; dataaccess.colSTCDesc2 = dataaccess.tblSTCPart.Columns["STCDesc2"]; da.Fill(ds, "StockParts"); da.Dispose(); tbl.Dispose(); col.Dispose(); cn.Close(); cn.Dispose(); Application.DoEvents(); StockParts = dataaccess.tblSTCPart.Rows[0]; this.StockID.Text = dataaccess.TextNull((string)StockParts[dataaccess.colSTCPartID]); this.Description.Text = dataaccess.TextNull((string)StockParts[dataaccess.colSTCDesc1]); this.Description2.Text = dataaccess.TextNull((string)StockParts[dataaccess.colSTCDesc2]); I but a button on the form to do a change and try to update the database string sql; cn = new OleDbConnection(dataaccess.STCConString); SQL = "SELECT STCPartID, STCDesc1, STCDesc2 FROM StockParts ORDER BY STCPartID"; da = new OleDbDataAdapter(SQL, cn); cn.Open(); OleDbCommand cmd; sql = "UPDATE [stockParts]"; sql += " SET STCPartID = ?, STCDesc1 = ?, STCDesc2 = ? "; sql += " WHERE STCPartID = ? AND STCDesc1 = ? STCDesc2 = ? "; cmd = new OleDbCommand(sql, cn); OleDbParameterCollection pc = cmd.Parameters; pc.Add("STCPartID_New", OleDbType.Char, 0, "STCPartID"); pc.Add("STCDesc1_New", OleDbType.Char, 0, "STCDesc1"); pc.Add("STCDesc2_New", OleDbType.Char, 0, "STCDesc2"); OleDbParameter param; param = pc.Add("STCPartID_Orig", OleDbType.Char, 0, "STCPartID"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("STCDesc1_Orig", OleDbType.Char, 0, "STCDesc1"); param.SourceVersion = DataRowVersion.Original; param = pc.Add("STCDesc2_Orig", OleDbType.Char, 0, "STCDesc2"); param.SourceVersion = DataRowVersion.Original; this.StockParts[dataaccess.colSTCDesc2] = "This Has Been updated By The Data Adapter"; da.UpdateCommand = cmd; da.Update(ds, "StockParts"); ds.AcceptChanges(); MessageBox.Show("The update was successful."); I get the following error on da.update(ds, "StockParts"); An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll but I get no additional information. If I use the command builder to create the update sql it gives me the following UPDATE StockParts SET STCPartID = ? , STCDesc1 = ? , STCDesc2 = ? WHERE ( (STCPartID = ?) AND ((? = 1 AND STCDesc1 IS NULL) OR (STCDesc1 = ?)) AND ((? = 1 AND STCDesc2 IS NULL) OR (STCDesc2 = ?)) ) But I still get the error in the same place. Any help on what I am doing wrong will be gladly received, also can anyone suggest a good book to read up on the SQL update, insert and delete commands. Thanks
  22. :rolleyes: Pennys Droped row.Table.Columns[0].ColumnName I think I will just forget everything I tried to do yesterday
  23. I don't think I have explaned what it is I am trying to do very well so I will go into more detail. First the database I am connecting to is in Access 2000. What I am hoping to do is to have a routine that will take a DataRow as a parameter. It will then look at all rows to see which have changed, if a row has changed get the row name and append it to a string to create an updatecommand that it will send back to the calling program. JABE Thanks for your reply, Yes you are right and I did actual know this, but for some reason I had trouble saying what I meant yesterday. :D I should have added that I was unsure how to go through the index as I didn't know how many columns there were. I have since found row.Table.Columns.Count that I believe will do what I want, So Yes, I can use the DataRow as you suggested to find out which columns have changed but I don't seem to be able to find a way to get the column name. Joe Mamma Thanks for your reply, I must admit that I don't actual know what triggers are as I have never used SQL Server, We have Novel here and I don't remember seeing them mentioned.
  24. JABE Thanks for the reply. I know about the DataRowVersion in DataRow.Item, the only problem with this is that it needs the Column name and I don't know it as I will be sending it lots of different tables.
  25. What I am trying to do is pass a row to a routine and make an update command that just contains the ammended columns. Problem Is I don't seem to be able to find a way off going through the rows columns collection to see if the current value is different to the original value, and if so then to get the columns name. Does any one know how to do this or how to just get the column name returned. Thanks
×
×
  • Create New...