|
I have a stored procedure that returns two result sets. How can we handle this in EF and calling this in C#? I know that this will be handled easily starting from .Net Framework 4.5. But I am using .Net Framework and EF version 4.0. Please provide any suggestions.
|
|
|
|
|
|
Hello fellow C# developers.
I am doing a little bit login system.I came to a point where I need to log my operations for every user. I made custom Log static class, because I don't need not used objects.
I have the following method in the class.
public static void Logging(string logMessage, string user)
{
using (Writer)
{
Writer.Write("\r\nLog Entry : ");
Writer.Write(
"{0} {1}\r\n user: {2}",
DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString(),
user);
Writer.WriteLine(": {0}", logMessage);
Writer.WriteLine("-------------------------------");
}
}
When I use it for the first time is OK upon button click events, but when I call it again, I get an Exception. I checked it and it was "Cannot write to a closed TextWriter". So what seems to be the problem?
Isn't using opening and closing the writer, so when I open it again it would be ok?
|
|
|
|
|
A using block will dispose of the resource (in this case, closing the TextWriter ) at the end of the block. It has nothing to do with creating the resource or opening the TextWriter .
Either change your code so that it creates the TextWriter on every call, or remove the using block and find another way to close the Writer when it's no longer needed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Guys,
I face issues in connecting to SQL Database on Server machine using C#, but am successful in creating connecting with local database in the system.
1. I enabled remote access (by making TCP protocol Enabled)
I have a server machine with SQL 2008 R2 Express Edition installed, and i have created a Database in that machine.
I cannot start "SQL Server Agent" - getting Remote Procedure Call Failed Error.
But other 2 are in running state (SQL Server (SQLEXPRESS) & SQL Server Browser)
Is that i cannot connect to this server Database using the SQL 2008 R2 Express edition ????
Do i need to have SQL Server 2008 R2 installed ??
Please assist.
|
|
|
|
|
You don't need to have SQL server installed on anything other than the server - that's the whole idea of having a server running SQL server: the other machines connect to the SQL server instance and access the DB via that.
Start by connecting to the server instance.
Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file to use from your C# code.
Until you have that working, you aren't going to get anywhere!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You have already posted this question below[^], and received a couple of answers.
Please DO NOT repost the same question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I keep getting an error message, and i am not sure why.
Error:
The variable name '@No' has already been declared. Variable names must be unique within a query batch or stored procedure.
Here is my code:
cmd.Connection.Open();
foreach (ListViewItem item in lstViewXML.Items)
{
cmd.Parameters.Add("@No", item.Text);
cmd.Parameters.Add("@ItemNo", item.SubItems[1].Text);
cmd.Parameters.Add("@Qty", item.SubItems[2].Text);
cmd.CommandText = "Insert into xml (No,ItemNo,Qty) VALUES (@No,@ItemNo,@Qty)";
cmd.ExecuteNonQuery();
}
cmd.Connection.Close();
cmd.Dispose();
|
|
|
|
|
Add
cmd.Parameters.Clear
after
cmd.ExecuteNonQuery();
Also move
cmd.CommandText = "Insert into xml (No,ItemNo,Qty) VALUES (@No,@ItemNo,@Qty)";
out of the loop
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Thank you, it's working now.
Can you explain why i had to move
cmd.CommandText = "Insert into xml (No,ItemNo,Qty) VALUES (@No,@ItemNo,@Qty)";
Out of the loop?
|
|
|
|
|
It's a constant value - why set every time?!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Thank you for your help 
|
|
|
|
|
You welcome...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
hi, I am working in C#.net and taking ms-access as backend for windows application. I want to auto generate one number in a particular pattern(eg. AB/2014/2/2).
Here AB: will be some fixed string
2014: present year
2:month
5:auto generate no.(will increment after submission of form)
whenever some one will fill the form and will click on submit button then this no. has to be generated. last digit in this no. is sequence no. which will be incremented after checking previous no.
this no. will act as a primary key in database.
can somebody help me out with this? I am not getting how to code this.....
|
|
|
|
|
You can configure the DB to automatically set the primary key on insert of a new record.
For the rest, set a date field where you store the date of submission.
On display, you can display the date and the primary key together, e.g. 2014/2/1231
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
|
Diya Bh. wrote: and also I have to add constant string value in the beginning of the number.
You'd have to separate that into two rows, e.g.:
row_PrimaryKey ------------------ row_PrimaryKeyPrefix
[It's a number, after all ]
___________________________________________________________
Diya Bh. wrote: can you please explain me how to configure?
1. Google[^]
2. Look at some of the results[^]
That's all I can tell you so far, for any more info you need to give more information about what you are doing
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
ok.
user will fill the form and after clicking on submit button all the details will be stored in the database along with id number(this auto generated number) that will be generated automatically in the format AB/2014/2/6.
AB is fixed
2014 is present year
2 is present month
6 is a no. that will be incremented after checking previous sequence no.
this generated no. will act a primary key in whole database.
There will be no textbox for this no.

|
|
|
|
|
Diya Bh. wrote: this no. will act as a primary key in database. It shouldn't; it breaks the first normal form, as it is a compound field that contains multiple pieces of information. A Primary Key should identify the record uniquely, and should NEVER contain a constant.
One of the most important rules in database-design; the primary key does NEVER contain other information than to identify the field. The end-user NEVER sees the PK. Explaining why is simple; your number might change in the real world, and you'd be updating all references to that PK.
Put your fake-number (it's not a number as it contains characters) somewhere as a normal field, and make it a calculated field.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
this no. is uniquely defining fields in database.
Bcoz only string value is constant and rest of the field in the generated no. will be automatically from the present year and month and most imp.
last field in that no. is sequence no. which will get increment after checking previous no.
this means.. 3 fields in that auto generated no. will be combined and will make unique primary key.
|
|
|
|
|
Diya Bh. wrote: this means.
You already explained your intention - I merely remarked that it is a bad design. Primary keys should not hold information, and should always be a single atomic fact. Another point is that one does not repeat a constant in each value - it'd be nonsense to store a constant that applies to each row, with each row. It's wasting space, and making indexes larger (=slower db). If one needs a constant added to a field, one would generally add that when formatting it (in the UI).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You already have four answers for your question asked on the C# 4.0 forum: [^].
Why post it here, also ?
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Is there a way of displaying SSRS report in MVC 4.
I googled and many articles are using reportviewer in webform and routing to that aspx page.
There should be a better way of doing this in MVC 4
|
|
|
|
|
|
the thing is my reports are created in SQL
either i can deploy them and use the link or i can use the RDLC file
which one is better solution and how to view existing report created in SQL
|
|
|
|