|
Use your catch clause properly to help you diagnose your problem; something like:
catch (Exception e)
{
MessageBox.Show("Error: {0}", e);
}
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i already try this and not found the problem .finally i found code that look the same and working
public partial class test1 : System.Web.UI.Page
{
public DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='"
+ Server.MapPath(@"App_Data\Database.mdf") + "';Integrated Security=True;User Instance=True";
string query = "select * from common";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(query, conn);
dt = new DataTable();
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close();
da.Dispose();
}
catch
{
MessageBox.Show("Error.....");
}
}
}
|
|
|
|
|
So you copied your classmates solution.
There is an error in your original code so technically its not the same. Your new assignment is to find the difference and post it here
|
|
|
|
|
Hello everyone,
I have a problem, i want to use the following namespace
System.Windows.Int32Rect not exist
but i can't find it or it doesn't exist.
How can i obtain it.
Thanks in advance,
z3ngew
|
|
|
|
|
The solution of this problem is to add the
WindowsBase.dll from the references of the framework
z3ngew
|
|
|
|
|
This is not a namespace but a structure. Or to be more precise:
Int32Rect is a structure that has been placed in the System.Windows namespace. If you cannot find it then you are missing the WindowsBase library.
|
|
|
|
|
Which version of .NET framework are you using? According to the documentation[^] this was introduced in 3.0.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'm using .Net FrameWork 4
z3ngew
|
|
|
|
|
I Define a user control that Inherits From Control Class
I want to show many instances of that class in a new class than inherits from Pannel Class
When I make instances and run this Code, there is no control in my Pannel:
This.Controls.add(new...);
modified 12-Jan-13 2:44am.
|
|
|
|
|
Without seeing the rest of the code, it's impossible to answer the question accurately.
Though, chances are good that you didn't set the Location property of any of the controls you created and they're all sitting on top of one another in the upper left corner of the panel.
|
|
|
|
|
Thankss a lot
this is the entire code:
public Mine[,] Mines;
public void Start()
{
this.Controls.Clear();
int counter = this.Bombs;
Mines= new Mine[Rows, Columns];
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < Columns; j++)
{
Mines[i, j] = new Mine()
{
IsColored = true,
IsHidden = true,
Location = new System.Drawing.Point(j*16,i*16)
};
this.Controls.Add(Mines[i, j]);
}
}
}
|
|
|
|
|
Two things you need to do: First, try setting a Size for each Mine: 10x10 will probably help.
Second, how are you sure that they aren't being added? Try setting a BorderStyle as well:
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < Columns; j++)
{
Mines[i, j] = new Mine()
{
IsColored = true,
IsHidden = true,
Location = new System.Drawing.Point(j * 16, i * 16),
Size = new Size(10,10),
BorderStyle = BorderStyle.FixedSingle
};
this.Controls.Add(Mines[i, j]);
}
}
See if you can see them then.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Hi,
I am new to the OOP in asp.net.
I have created a console application, within which I call another class, let us call it class A.
I want to logging of events going on in the application.
I am using the app.config, the define the log file path. and using simple System.IO.File.WriteAll to write to this file.
But for some reason, the log captures only the statements written in the main part of the app and not what was logged in class A. I am writing to the same log file.
How can I make it so the log file keeps appending??
Much appreciated!!
|
|
|
|
|
Try using something like log4net or NLog both of which are free and easy to use, rather than rolling your own. I use log4net in a console application and it writes clear and concise log files with pipe-delimited fields; so easy to parse and view, if required. Very quikc and easy to set up and integrate into your code.
No real way to know what is wrong with your code if you don't provide samples/exceptions.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
yup - while I have some issues with log4net (I use a custom startup so I can dynamically define where the log file goes based on where the app exe is located, rather than a fixed path/location for log files), I'd recommend it to anyone starting out using/needing logging
|
|
|
|
|
I have tried the Nlog tool. It worked well with one project, and when I tried to add it to another project, it was a complete mess. I was not able to add the config file specific to this second project.
I read that you need to install the tool, not having any pojects opened, just only the VS opened. I did that as well, but it was not straight forward.
|
|
|
|
|
Can you have the class A raise an event and have the parent class attach a handler to write the log? I've done that in the past for similar situations.
|
|
|
|
|
I used Nlog for logging.
It has a separate config file, and specifies the path to log all the application events.
I want to send this log file in an email. How would I get the path to this location in my program?
|
|
|
|
|
Dunno. Never used it. Can't you read the config file?
|
|
|
|
|
Hello Everyone this is my first question I am posting!
I need help with a code
I need to count the same books I have added to a Binary File and show that number in the console but since I am new with these types of codes i am seeking for your help
This is the code i have Written to add the books to the file and I also have the code to read the files (if needed will post it) Now the problem is i don't know how to count the same book i have added multiple times and show it in Console. If anyone can help me i will appreciate it
If u need any explanation let me know and i will try to explain with my knowledge
Thanks in Advance
{
class Class1
{
internal void AddBooks()
{
string addBook = "";
while (addBook != "No")
{
Console.WriteLine("========================================");
Console.WriteLine("Write the Books Identifiing number u want to add");
int bookNumber = int.Parse(Console.ReadLine());
Console.WriteLine("Write Books Titttle");
string bookTittle = Console.ReadLine();
Console.WriteLine("Write th Authors Name");
string authorName = Console.ReadLine();
Console.WriteLine("Write the publishing company ");
string pubCompany = Console.ReadLine();
FileStream fsBooks = new FileStream("Books.bin", FileMode.Append, FileAccess.Write);
BinaryWriter bwBooks = new BinaryWriter(fsBooks);
bwBooks.Write(bookNumber);
bwBooks.Write(FillBlanks(bookTittle, 30));
bwBooks.Write(FillBlanks(bookTittle,25));
bwBooks.Write(FillBlanks(pubCompany, 15));
bwBooks.Flush();
Console.WriteLine("==========================");
Console.WriteLine("Do You Want to add another Book: 'Yes'/'No' ");
addBook = Console.ReadLine();
bwBooks.Close();
fsBooks.Close();
}
}
static string FillBlanks(string text, int size)
{
string blanks = "";
if (text.Length < size)
{
int difference = size - text.Length;
for (int i = 0; i < difference; i++)
{
blanks += " ";
}
}
else if (text.Length > size)
{
text = text.Substring(0, size);
}
return text + blanks;
}
}
}
|
|
|
|
|
first of all, look closely at your code to write to your file - why are you writing booktitle twice ? - should you not be writing your author somewhere there ?
bwBooks.Write(FillBlanks(bookTittle, 30));
bwBooks.Write(FillBlanks(bookTittle,25));
bwBooks.Write(FillBlanks(pubCompany, 15));
(btw, I think you should carefully consider if thats the most appropriate design for your file)
second, think about your problem like this... for every book read from your binary file, you want to store (possibly) the book title, and a count of how many times that title appears .. so, you could store the book title and a count in a dictionary or hashmap type object, eg
Dictionary <string, int> booktitle_counts;
So, every time you read a book, check if its already in the dictionay - if it is, increment the count for that book - else, insert the book and a count of '1'
At the end of reading your file back, you loop through the dictionary, writing the titles where count > 1.....
|
|
|
|
|
bwBooks.Write(FillBlanks(bookTittle, 30));
bwBooks.Write(FillBlanks(bookTittle,25));
bwBooks.Write(FillBlanks(pubCompany, 15));
the book tittle is a mistake i have made
this the code I use to read the Books
<pre lang="c#">public static void ReadBooks()
{
bool found = false;
Console.WriteLine("Write the number u are looking for");
int wantedNR = Int32.Parse(Console.ReadLine());
FileStream file = new FileStream("Books.bin", FileMode.Open, FileAccess.Read);
BinaryReader binReader = new BinaryReader(file);
while (file.Position!=file.Length)
{
int bookNumber = binReader.ReadInt32();
if (bookNumber==wantedNR)
{
found=true;
string bookName = binReader.ReadString();
string authorName = binReader.ReadString();
string pubCompany = binReader.ReadString();
Console.WriteLine("============================================");
Console.WriteLine("Book Number:" + bookNumber);
Console.WriteLine("Book Name:" + bookName);
Console.WriteLine("Author:" + authorName);
Console.WriteLine("Publishing Company:" + pubCompany);
Console.WriteLine("===========================================");
break;
}
else
{
binReader.BaseStream.Seek(73, SeekOrigin.Current);
}
}
binReader.Close();
file.Close();
if (found == false)
{
Console.WriteLine("The Wanted Number u are looking for{0} doesn't exist in this file", wantedNR);
}
}
if u can help me and tell me how to use this Dictionary thing u posted(since this is the first time I see it) it would help me lot since I really don't know how to do this
|
|
|
|
|
well, Im not going to do all your work for you - as a programmer, you are expected to know how to research for example. So, here's a start point for using a dictionary
http://www.dotnetperls.com/dictionary[^]
... and you have most of the code you need in ReadBooks
So, I would do a number of phases
1) copy all the code in ReadBooks() to a new method called (for example) ReadAllBooks
2) remove the input/check logic from ReadAllBooks so that it prints the entire file - make sure this works before proceeding !
3) Once (2) is working, add (for example)
Dictionary<String, Int> booktitle_counts = new Dictionary<String, Int>();
and the logic I outlined in my first reply for checking if a booktitle exists and adding it if it doesnt or incrementing the counter if it does already exist
4) Then you simply need to remove the book print code, and add some code to loop through the dictionary looking at the book title vs counts - big hint - look at the reference I gave you and see 'foreach'
Learn how to break your problems down into small chunks - then build up/extend code, making sure the basic parts work first, and each subsequent change works
|
|
|
|
|
Thank You very much for your Help
I will now read the content of the web page u sent me and will check if i can do it
Thanks aggain
|
|
|
|
|
Hello fellow coders, I was wondering if anyone ever experienced any latency in the button click when using the MVVM approach? I have 4 buttons and it seems when I click on either one initially there's a 3 second latency before the text changes and the other buttons become disabled. After that initial click it runs quicker. No matter which button it is on that first click it takes 3 seconds to respond then after that each button responds immediately. So here is what I'm doing.
1. I'm using the RelayCommand that was located in Josh Smith's article.
2. I have the following setup in my xaml behind my buttons. Each button has a different CommandParameter.
<Button x:Name="btnAddSaveUpdate" Content="{Binding AddSaveUpdateContent}" Style="{StaticResource ButtonStyle}" Command="{Binding AddSaveUpdateCmd}" CommandParameter="AddSaveButton" />
3. In the creation of my mobileViewModel I have the following code in the constructor. I assign the AddSaveUpdateContent property to update the text. Note, that this property has an OnPropertyChanged call inside.
_addSaveUpdateCmd = new RelayCommand(param => OnExecute(param), this.CanExecute);
AddSaveUpdateContent = "Add";
4. Inside the CanExecute is a case statement that gets the CommandParameter:
case "AddSaveButton":
return true;
5. Inside the OnExecute is another case statement that gets the CommandParameter as well then calls another method:
case "AddSaveButton":
PerformButtonTask(AddSaveUpdateContent);
break;
6. Then in my PerformButtonTask method all I'm doing is is running through one more case statment to perform the appropriate task. The EnableFields and ClearFields are events that call a method in the code behind on the xaml page.
case "Add":
AddSaveUpdateContent = "Save";
ExitCancelCmdContent = "Cancel";
ClearFields();
EnableFieldsEvent(true);
break;
That's pretty much it. So, if anyone has any ideas please share. Thanks.
Update: Just to let you know. The problem is occurring in Visual Studio 2012 in debug mode; however, when I create my executable the response is immediately as expected. So, is because of the development environment?
Tee123
|
|
|
|