|
I have this line:
string sAuthor = (string)oDataSet.Tables[0].Rows[0]["Author"];
On some rows the Author is null, so I get a cast error. I'm not sure what to do about this. Can someone help.
Everything makes sense in someone's mind
|
|
|
|
|
Take a look at the DataRow.IsNull method. That might do what you want.
Tony
|
|
|
|
|
simply use
try
{...}
catch
{sAuthor = null}
you are processing nulls so should be ok
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
This answer gave me another idea... I believe that the prefered way of dealing with casts in c# is to use:
string sAuthor = oDataSet.Tables[0].Rows[0]["Author"] as string;
This sets sAuthor to null when it can't be converted to a string, and shouldn't (hopefully) cause an exception.
Tony
|
|
|
|
|
I understand your code here,
in datagridview when i am processing null values i use ...=dbnull.value, like you used tablerow.isnull (never used that before d´ont know here) for a table, but like he is not sending data do a database or whatever table, he has to do string X = null, because he is setting a string not a Dgv or a table, string X = dbnull.value or string X = tablerow.isnull wouldn´t work.
You just forgot that or not noticed, its simply i know you know that, i make errors in really simply things all the time, makes me mad
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
I have the dataset bound to textboxes on the form:
txtTitle.DataBindings.Add("Text", oDataSet, "ItemRow.Title");
txtCategory.DataBindings.Add("Text", oDataSet, "ItemRow.Category");
txtAuthor.DataBindings.Add("Text", oDataSet, "ItemRow.Author");
txtCatNo.DataBindings.Add("Text", oDataSet, "ItemRow.Catalogue_No");
txtIsbn.DataBindings.Add("Text", oDataSet, "ItemRow.Isbn");
txtPublisher.DataBindings.Add("Text", oDataSet, "ItemRow.Publisher");
In SaveChanges I then pass the oDataSet variable to this code in my Data Access class:
public bool UpdateDataSet(DataSet oDataSet, string sTableName)
{
bool bRetVal = true;
try
{
DataRow oRow = oDataSet.Tables[0].Rows[0];
DataRowState state = oRow.RowState; \\state = Unchanged
oAdapter.Update(oDataSet, sTableName);
}
catch(SqlException e)
{
oException = e;
bRetVal = false;
}
return bRetVal;
}
The DataAdapater is stored as oAdapter on the data access class. When I run this, it doesn't error, but it also doesn't save. Notice that the RowState is unchanged at this point.
I'm not sure what I'm missing here.
Everything makes sense in someone's mind
|
|
|
|
|
The insert and update commands need to be defined as well as verifying that the row state allows for an update. Personally, I do not use the Dataset for updates as it makes such a simple thing complicated.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Isn't that the purpose of the SqlCommandBuilder?
I have:
public DataSet ExecuteQuery(string sCommand, string sTableName)
{
bool bError = false;
DataSet oDataSet = new DataSet();
DataSet oRetVal = null;
SqlConnection oConn = GetConnection(false);
oAdapter = new SqlDataAdapter(sCommand, oConn);
SqlCommandBuilder oBuilder = new SqlCommandBuilder(oAdapter);
try
{
oAdapter.Fill(oDataSet, sTableName);
}
catch(SqlException e)
{
oException = e;
bError = true;
}
if(! bError)
{
oRetVal = oDataSet;
}
return oRetVal;
}
Everything makes sense in someone's mind
|
|
|
|
|
hi
do you have any example that to report(crystalreport) from proc(sql server 2005)?
thanks a lot
|
|
|
|
|
Yes, I have plenty. However, an example is not necessary. In the report creation wizard you can select ADO.NET as the report source, and then select a stored procedure from the list that appears. (If memory is failing me you may have to select ODBC source and not ADO.NET since I think ADO.NET is for datasets only)
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
thanks for your answer
but i have problem about to send parameter to proc
please send me 1 or 2 example
i need it
thank you very much
|
|
|
|
|
Hi,
I use conditional compiling via to block login dialogs while debuging.
#if DEBUG
sSqlUserName = "me";
sPwd = "123456";
#else
#endif
This work well and saves me typing my user name and password a thousand times.
However I was wondering if any of the code or strings inside the if #DEBUG make it into the exe when compiling the release version. If they do, I suppose one should make sure to remove the hard coded user name and password prior to releasing the app.
Anyone know how this works?
Thanks.
Tim
|
|
|
|
|
They won't be compiled into the exe unlesss the DEBUG directive is defined.
You can also examine this using a free tool named .NET Reflector[^].
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
With the bad habit of debug builds getting passed into production I would make your own preprocessor declaration and then add it to your personal projects build options.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
And let that slip into production rather
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
My build settings don't get checked in so ...
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: My build settings don't get checked in so ...
Compilation directives are stored in the csproj file. I sure as hell hope you check that in, unless you some sadist bastid that let others create their own project files...
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
You know me better than I know myself ...
Actually, I keep my local project file writable unless I am adding files and such because I don't like to check in settings like you said.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
StringBuilder results = new StringBuilder();
//Create GPO Table
results.Append("Creating GPO Table");
DataTable GPOtable = new DataTable("Group Policy");
DataColumnCollection GPOCol = GPOtable.Columns;
GPOCol.Add("GUID", typeof(string)).Unique = true;
GPOCol.Add("Name", typeof(string));
GPOCol.Add("Domain", typeof(string));
GPOCol.Add("Created", typeof(DateTime));
GPOCol.Add("Modified", typeof(DateTime));
GPOCol.Add("Status", typeof(string));
// Set Primary Key
results.Append("Creating primary key");
GPOtable.PrimaryKey = new DataColumn[] { GPOCol["GUID"] };
//Add table to Dataset
results.Append("Saving new table to Database");
DataSet1.Tables.Add(GPOtable);
I am trying to save this new table to an access database, i have the database connection setup in my app.config and the dataset1 is the dataset to the DB
Is there something I am doing wrong in the code above?
|
|
|
|
|
Yes, you can't do what you're code is describing. You cannot create tables and columns in a DataSet object and expect it to automatically create the appropriate tables and columns in the database. It doesn't work like that.
You have to generate and execute the appropriate SQL Statements against the database directly to do this. You cannot use a DataSet object to do it for you.
|
|
|
|
|
I have developed a winforms app running on Windows XP on a Wyseterm S90, which needs to be running constantly to register cardswipes from a remote device (connected via serial over cat5) and display on a remote monitor (vga over cat5). Everything runs sweetly up until the point that the S90 terminal decides that as it hasn't had a mouse movement or keypress recently, and flips the monitor into standby. So far I have:
Checked the power management and screensaver settings - both set to permanently on
Checked the group policy for the account logged into the device
Added some code to "jiggle" the mouse by a pixel every other second, via both Cursor.Position and OnMouseMove
Nothing seems to persuade the device to stay awake, and I'm almost out of letters to assign to my cunning plans. Can anyone suggest any more alternatives? Is there a SystemEvents event that I can catch and/or trigger to keep the little blighter alive?
Thanks in advance,
Al
|
|
|
|
|
The last two posts on this page[^] may help.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks for this Dave - it definitely seems to be pointing in the right direction.
|
|
|
|
|
I have added shared remote printers to a machine as follows:
printer1 on printserver
printer2 on printserver
printer3 on printserver
...
There is also a local shared printer on this machine.
i.e. printerLocalA
I am not sure why my code does not read the list of the remote printers. It only reads the printers that are local i.e. PrinterLocalA.
This is what I am using and it seems the code is correct but there is something wrong with the way the printers are added I think.
Do you agree?
Any solutions please?
using system.printing;
PrintServer myPrintServer = new PrintServer(@"\\" + txtServerName.Text.Trim());
// List the print server's queues
PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
foreach (PrintQueue pq in myPrintQueues)
{
comboBox3.Items.Add(pq.Name);
}
Thanks
|
|
|
|
|
hello everybody
i have a function that save my datatable to an excel file:
int columnIndex = 0;
Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
foreach (DataColumn dc in dataSet.Tables[1].Columns)
{
columnIndex++;
excel.Cells.ColumnWidth = 25;
excel.Cells[1, columnIndex] = dc.ColumnName;
}
int rowIndex = 0;
foreach (DataRow dr in dataSet.Tables[1].Rows)
{
rowIndex++;
columnIndex = 0;
foreach (DataColumn dc in dataSet.Tables[1].Columns)
{
columnIndex++;
excel.Cells[rowIndex + 1, columnIndex] = dr[dc.ColumnName];
}
}
excel.Save(@"C:\SomeName.xls");
what is going on is that a pop up window ask me "if i need to save my excel sheet', if i agree both files are saved one in c:/someName.xls and another for the pop up window. i don't want the pop up to be displayed i just need to save programatically my datatable.
i'm new in excel things please any help
kind regards
|
|
|
|