|
Well, I've tried and I guess you meant it this way.
public void WriteToFile()
{
using (StreamWriter swb = new StreamWriter(Filename))
{
for (int i = 1; i <= (listBoxBlockedNumberDD.Items.Count+1); i++ )
{
<big>swb.WriteLine(listBoxBlockedNumberDD.Items[i].ToString());</big> }
swb.Close();
}
}
But now, the Big line threw error :
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: ArgumentOutOfRangeException
Parameter name: index
How could this happen?
irsalina [student]
|
|
|
|
|
I am trying to compare dates from my C# project file to the dates from my database. What I want to achieve is to check if the same date occured in the database. How do I do this? For example I want to check if DateTime.Now already existed in the database. I am trying to read it from there, however I need only the date, not the time. I have to omit this, because my plan was to convert them to strings and then just compare if they existed already. Can anyone help?
|
|
|
|
|
just call .Date on the date object.
DateTime.Now.Date
Simon
|
|
|
|
|
LOLZ!!! Stupid me! Thanks!
|
|
|
|
|
No worries. It's easily missed if you don't know it's there.
Simon
|
|
|
|
|
The same can also be done by calling DateTime.Today
|
|
|
|
|
Hi,
I have a sql database with data about customers. I made it possible to add/change/remove customers from the gridview.
The customer's data are stored in a sql database. Suppose the user adds/changes/removes a row/cell in my gridview.
How can i update the changes made in the gridview in the datatable?
The idea behind all this is to update the sql database as much as possible 'automatically'.
This is a peace of my code:
dbCommand.CommandText = "SELECT firstName, LastName FROM Customer";
customerAdapter = new SqlDataAdapter(dbCommand.CommandText, connectionString);
reader = dbCommand.ExecuteReader();
// Populate a new data table and bind it to the BindingSource.
customerTable = new System.Data.DataTable();
customerAdapter.Fill(customerTable);
grdcustomerManagement.DataSource = customerTable;
Any idea's?
|
|
|
|
|
Use the same DataAdapter and call its Update method.
|
|
|
|
|
Hi,
I tried that, but it's giving me an error (which is in dutch) about 'delete command'.
I used the update method of the data adapter in the Rowsremoved event of the gridview.
|
|
|
|
|
Ah. You need to create a CommandBuilder object on that DataAdapter so it can fill in the missing SQL insert, delete, and update queries that the adapter needs.
Or, you could just add those Command objects to the DataAdapter yourself.
|
|
|
|
|
Hi,
Any chance you can give me a code sample? I've tried a few i found on the net. But no luck.
|
|
|
|
|
There is a single line of code you add to the creation of the DataAdapter to do this. I cannot believe you didn't find an example that explains this.
dbCommand.CommandText = "SELECT firstName, LastName FROM Customer";
customerAdapter = new SqlDataAdapter(dbCommand.CommandText, connectionString);
Dim cb = new SqlCommandBuilder(customerAdapter);
customerTable = new System.Data.DataTable();
customerAdapter.Fill(customerTable);
|
|
|
|
|
Hi,
I was actually talking about how to update the datatable after a few rows have been removed.
I already got those lines in my application.
I tried updating the datatable with customerAdapter.Update() method.
But it's complaining about a deleteCommand.
So after some rows have been removed from the gridview which i caught in the event handler of the datagridview, how do i update the datatable and update the sql database with the customerAdapter.Update() method?
[EDIT]
Ah never mind, i see what i was doing wrong. I forgot to put the adapter inside the () of the commandbuilder instance.
Thank you, it works perfectly now!
[/EDIT]
modified on Friday, December 12, 2008 2:37 AM
|
|
|
|
|
I am facing problem with ReportViwer during excel file creation. excel format is not proper, it's height is constant. Is there any property by using which i can set the width of excel sheet.
My code is
fileSaveDialog.ShowDialog();
if (fileSaveDialog.FileName != string.Empty)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = this.rvAuditTrail.LocalReport.Render(
type, null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
// this.rvAuditTrail.LocalReport.SetParameters(
//ReportParameter
FileStream fs = new FileStream(fileSaveDialog.FileName,
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
Truth Is The Simplest !!!!
|
|
|
|
|
Afternoon all,
I'm trying to tidy up my code a little and wondered if its possible to add a number of object to a list on one line of code.
i.e
zooAnimals.Add(newcat1);
zooAnimals.Add(newcat2);
zooAnimals.Add(newtig1);
zooAnimals.Add(newtig2);
is there a way of putting these all in the one statement ?
Something like,
zooAnimals.Add(newcat1),(newcat2),(newtig1),(newtig2);
(I know the above DOESN'T work, it's just there to readers an idea of what i mean)
Thanks
Neil
modified on Thursday, December 11, 2008 8:57 AM
|
|
|
|
|
There is a method 'AddRange' that takes a enumerable such as an array or something like that.
Simon
|
|
|
|
|
For adding multiple values at a time you need another collection which contains all the item that you want to add and do it as
zooAnimals.AddRange(newarr);
newarr can be any collection which is inherited from IEnumerable.
Cheers!!
Brij
|
|
|
|
|
As others have said, you need to put the objects into an ArrayList , but IMHO, that would be a waste of time if that's the only reason you're creating the ArrayList . At some point, you have to add them one at a time *somewhere*, so why not just do it without an intermediate data structure? Just add them one at a time and be done with it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Thursday, December 11, 2008 11:37 AM
|
|
|
|
|
Hi
Try this:
object[] myObjects = new object[] { newcat1, newcat2, newtig1, newtig2 };
ArrayList myArrayList = new ArrayList(myObjects);
It should keep things nice and tidy for you...
oooo, the Jedi's will feel this one....
|
|
|
|
|
assuming ZooAnimal is the type held by zooAnimals, you can do:
zooAnimals.AddRange(new ZooAnimal[]{newcat1,newcat2,newtig1,newtig2});
which creates a temporary array and adds its content to zooAnimals.
|
|
|
|
|
I think if yo use completely random names for things, you could obfuscate it more.
(Yes, I'm one of those weird Outlaw Programmer moods today. Nobody is safe.)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I have the following code which stores the filenames in an array. However, I want only the filenames to be stored. Surely there is an easy way to do this? I know I can replace the line, imageNames.Add(img); with imageNames.Add(img.Remove(0, 22)); which will remove the path (first 22 chars) leaving just the filename but this will be different when I upload to my server so don't really want to do it this way. Any ideas will greatly appreciated.
foreach (string img in Directory.GetFiles(imagesDir, "*.jpg"))
{
imageNames.Add(img);
}
Many thanks
Lorna
|
|
|
|
|
hello
DirectoryInfo di = new DirectoryInfo(Path........);
FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach (FileInfo fi in rgFiles)
{
// add u r needs
}
|
|
|
|
|
Thanks but is that not the same as what I have and I get the complete path - here is another 2 lines of the code:
ArrayList imageNames = new ArrayList();
string imagesDir = Server.MapPath("~/administration/uploaded/");
foreach (string img in Directory.GetFiles(imagesDir, "*.jpg"))
{
imageNames.Add(img);
}
thanks
Lorna
|
|
|
|
|