|
Hi All,
I have a Windows service that suppose to write in a file in a shared network drive.
Bud im getting this error:
System.UnauthorizedAccessException: Access to the path '\\Pc001\test\test.txt' is denied.
How can i fix this ?
Thanks
|
|
|
|
|
You have to give wright permissions to the shared folder.
|
|
|
|
|
Run the service under a user account insterad of Local System. Start -> Run -> services.msc and find your service, double-click it to get properties. On the LogOn tab, specify a user account that has permissions to that network share.
|
|
|
|
|
Hi Dave Kreskowiak,
Thanks for reply, i will try this your suggestions asap.
|
|
|
|
|
|
Noone is going to answer you because of 3 things. First, your subject line demanded an answer. That is very rude.
Second, noone can understand your requirements. I understand English is not your native language, so someone else better at translating would probably be appropriate.
You question seems to be so high-level and undefined and to only elicate more questions from anyone who reads it.
|
|
|
|
|
hi all
i am new about in c# and making a small project to improve myself and to learn new things...but as u can imagine i have a problem...i have a datetimepicker in my form and i keep the customer's birthdate with it...but it tries to save the birthdate to database like dd.mm.yyyy...i use sql server 2005 express edition for database and it keeps that data as yyyy.mm.dd so how can i get rid of that problem..i want it to keep data as dd.mm.yyyy...and i keep my data in database as smalldatetime...i dont want to keep it as string because maybe i will make someoperations on it later...thanks for your help now
|
|
|
|
|
Without seeing your code, it is difficult to answer accurately, but:
I assume from your brief description that you are using DateTimePicker.Text to access the selected date? If so, then DateTimePicker has a Value property, which is a DateTime.
Use code similar to the following to insert the date into the database:
DateTime dt = dateTimePicker1.Value;
SqlCommand cmd = new SqlCommand("INSERT INTO myTable (DateColumn) VALUES (@DT)");
cmd.Parameters.AddWithValue("@DT", dt);
...
You are absolutly right not to keep the date in the database as a string! A DateTime or SmallDateTime is much better.
[edit]Types wrong: should be DateTime and SmallDateTime[/edit]
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
hey man thanks for the reply
it works very well but i want to ask one more question which is the date is kept like in that format in database 2009-12-28 15:47:18.250
my first question is that if it causes any problem when i want to read it from my database ??
and second one if it is possible to change that format as 28.12.2009 15:47:18.250
|
|
|
|
|
You can convert date time in different formats,check this link[^].
Regards.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I just finished an article on date/time issues, see here[^].
|
|
|
|
|
Glad it works - just to add the the other replies, when you read it from the database, keep it as a DateTime:
MySqlCommand cmd;
cmd = new MySqlCommand("SELECT date FROM myTable" +
" WHERE userId=@ID");
cmd.Parameters.AddWithValue("@ID", userId);
DataTable dt = Utilities.GetData(cmd);
if ((dt.Rows != null) && (dt.Rows.Count > 0))
{
DataRow dr = dt.Rows[0];
DateTime lastGoodLogin = (DateTime)dr["date"];
...
}
Then just format it as you wish when you need to present it to the user, either in a report on on-screen. DateTime (both DB and .NET) are an internal format - similar to "milliseconds since Jan 1st 2009" but with an internal date you (and I) don't need to know.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hi, I have created a class customer and where I am fetching all the records from the customer table through the procedure. Now I want to fetch all the distinct city from the customer table.
Here is the code
p
ublic List<City> GetAllDistinctCity()
{
EntityDataMode entity = new EntityDataMode (Connection.ConnectionString);
try
{
var collection = entity.GetAllCustomer();
}
catch (Exception ex)
{
}
}
If I create the view for the city, then I can directory fetch all the distinct city through the procedure, but I do not want to create any separate view for only city, which is a field of a customer table, because later I need to fetch another distinct field, then I have to again create a view for that field. Is there any simple method by which I can fetch distinct city using the GetAllCustomer() procedure
Pankaj
|
|
|
|
|
I am trying to create 2 separate tables and print them in word, however I end up with two tables which are attached to each other..how do i differentiate between the two tables?or how do i seperate the two tables?is there a way in which i can insert a paragraph/break between the tables..can anyone please help?
1st of all im adding word files to listview.....with diff pname n date...i need to display in different tables...those files im adding/....
plzz see my code then u ll get idea...
private void btnsave_Click(object sender, EventArgs e)
{
List<string> DoctorNames = new List<string>();
List<string> dte = new List<string>();
List<string> pname = new List<string>();
foreach (ListViewItem litem in listView1.Items)
{
if (DoctorNames.Contains(litem.SubItems[4].Text) == false)
DoctorNames.Add(litem.SubItems[4].Text);
}
List<string> list1 = new List<string>();
List<string> list2 = new List<string>();
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
foreach (string name in DoctorNames)
{
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = name.ToString();
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();
Microsoft.Office.Interop.Word.Paragraph oPara2;
oPara2 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara2.Range.Text = "Date:" + dte.ToString();
oPara2.Range.Font.Bold = 1;
oPara2.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara2.Range.InsertParagraphAfter();
string query = "Select FileName,LineCount from tbl where PName='" + name + "'";
OleDbDataAdapter da = new OleDbDataAdapter(query, oldb);
DataSet ds = new DataSet();
int a = listView1.Items.Count + 1;
Microsoft.Office.Interop.Word.Table oTable;
Microsoft.Office.Interop.Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng, a, 3, ref oMissing, ref oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;
oTable.Cell(1, 1).Range.Text = "SNO";
oTable.Cell(1, 2).Range.Text = "FileName";
oTable.Cell(1, 3).Range.Text = "Total Count";
for (int r = 1; r < a; r++)
{
oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;
oTable.Rows[r].Height = oWord.InchesToPoints(0);
}
oTable.Columns[1].Width = oWord.InchesToPoints(0); //Change width of columns 1 & 2
oTable.Columns[2].Width = oWord.InchesToPoints(0);
oTable.Columns[3].Width = oWord.InchesToPoints(0);
oTable.Rows[1].Range.Font.Bold = 1;
}
}
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">@nisha 2n wrote:</div>
for (int r = 1; r < a; r++)
{
oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;
oTable.Rows[r].Height = oWord.InchesToPoints(0);
}
</blockquote>
I do not see where you are creating two different tables. Perhaps that code is being called else where?
Try:
if(ThisDocument.Tables.Count == 0)
oTable = ThisDoucument.Tables[0];
else
oTable = ThisDoucument.Tables.Add(wrdRng, a, 3, ref oMissing, ref oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;
oTable.Cell(1, 1).Range.Text = "SNO";
oTable.Cell(1, 2).Range.Text = "FileName";
oTable.Cell(1, 3).Range.Text = "Total Count";
for (int r = 1; r < a; r++)
{
oTable.Cell(r + 1, 1).Range.Text = r.ToString();
oTable.Cell(r + 1, 2).Range.Text = listView1.Items[r - 1].SubItems[2].Text;
oTable.Cell(r + 1, 3).Range.Text = listView1.Items[r - 1].SubItems[7].Text;
oTable.Rows[r].Height = oWord.InchesToPoints(0);
}
oTable.Columns[1].Width = oWord.InchesToPoints(0);
oTable.Columns[2].Width = oWord.InchesToPoints(0);
oTable.Columns[3].Width = oWord.InchesToPoints(0);
oTable.Rows[1].Range.Font.Bold = 1;
Just make sure you are indexing the correct table in the document.
~TheArch
|
|
|
|
|
hii,,,,,,
yah...im getting multiple tables.....
Actualy my proj is on linecount for Word files......
soo 1st im using list view for add some files .when im adding those
files i hav to select diff pysician name n date.........it ill stores
into data base((convert MS ACCESS data to MS Word))
n then whn im save that data ,then,,it ll b save in single word doc in
different tables..by selectd pysician name n date,..
....BUT iam getting repeating in one table lik...
Dr.Name:Dr.Jhon
Date:20/12/2009
Sno| FileName |Count
1 Hobbs.doc |36.31
2 Horn.doc |45.72
3 McMillan.doc |41.49
4 Smith.doc |10.72
Dr.Name:Dr.king
Date:22/12/2009
Sno |FileName |Count
1 Hobbs.doc |36.31
2 Horn.doc |45.72
3 McMillan.doc |41.49
4 Smith.doc |10.72
..........................................................................
this is actully i want 2 get....
Dr.Name:Dr.Jhon
Date:20/12/2009
Sno| FileName| Count
1 Hobbs.doc |36.31
2 Horn.doc| 45.72
Dr.Name:Dr.king
Date:22/12/2009
Sno| FileName |Count
1 McMillan.doc |41.49
2 Smith.doc| 10.72
|
|
|
|
|
Hi i have a requirement to extract a portion of image from tif/jpeg/bmp images using C# and paste that extracted image into an excelsheet.
Anyone is already done this before?
pl provide me some helpful info regarding this.
Advanced thanks for your help.
|
|
|
|
|
To extract a portion, you need to draw a portion of the original image into the source image, and use the Clipboard.SetImage method. From there, you simply have to let the user paste it into Excel, or do some interop and place it in yourself.
|
|
|
|
|
I am trying to write a small function in C# by passing this DNS name www.google.com
And the function should return the host IP , it is like querying DNS server!
I wrote the following program , but it seems there this Warning
Warning 1 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is obsolete for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' D:\CoDoNS\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 26 20 WindowsFormsApplication1
Using System;
Using Sytem.Net;
namespace BuilderExamples {
class BuilderIPAddress {
static void Main(string[] args) {
try {
IPHostEntry iphe = Dns.Resolve("www.google.com");
foreach (IPAddress addr in iphe.AddressList)
{
Console.WriteLine("AddressFamily: " + addr.AddressFamily.ToString());
Console.WriteLine("Address: " + addr.ToString());
}
}
catch (Exception e) {
Console.WriteLine("Error: " + e.ToString());
}
} } }
Why Dns.Resolve Method in C# is obsolete ?
is the a workaround to get that function done?
Thanks
|
|
|
|
|
Well, the warning message is already giving you the answer.
Use Dns.GetHostEntry: IPHostEntry iphe = Dns.GetHostEntry("www.google.com");
|
|
|
|
|
it works
but what is meant by "obsolete"?
Thanks my friend
|
|
|
|
|
"Obsolete" : "No longer in use"[^]
In practice, it means you should not use it for new projects; there is a better equivalent. If you do use it, be aware that future releases of the IDE may not support it, or may not support it fully. On your own head be it!
Would you specify a 80386 based computer for a new project? It is obsolete too.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I am working on creating a Datagridview Cell with a combobox which is having multiple columns in C#.I got the idea about multicoulumn combobox but i am having difficulty in implementing it to a datagridviewcombobox. Can anyone help me?
|
|
|
|
|
The canned DataGridViewComboBox does not support multi-column functionality; you'll need to implement a custom column to host your own combo box and set the proper options in order to allow it to be multi-column. Refer to the below article for information on creating custom DataGridView column classes, it's actually not that difficult to do; I've made a few custom columns using this information as the basis.
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx[^]
Hope in one hand and poop in the other; see which fills up first. Hope and change were good slogans, now show us more than words.
|
|
|
|
|
how do i make such an application which is web based but multipoint sdk based also
please reply
thanks in advance
|
|
|
|