|
Hi, I am trying to upload an Excel file by passing excel data as User Defined Datatype to a stored Procedure using Entity Framework and C# Code in an ASP.Net Application as below:
public System.Int32 UploadServiceProgram(List<ServicePrograms_Upload> serviceProgList, string Fiscal_Period_Code, string CreatedBy)
{
DataTable serviceProgramDataTable = new DataTable();
serviceProgramDataTable.Columns.Add("ServiceCode", typeof(string));
serviceProgramDataTable.Columns.Add("ProgramCode", typeof(int));
serviceProgramDataTable.Columns.Add("UnitTypeDesc", typeof(string));
serviceProgramDataTable.Columns.Add("RateCap", typeof(decimal));
serviceProgramDataTable.Columns.Add("CountyCode", typeof(string));
foreach (var item in serviceProgList)
{
serviceProgramDataTable.Rows.Add(item.Provided_Service_Code, item.Program_Code, item.Unit_Type, item.Rate_Cap);
}
var parameter = new SqlParameter("@ServiceProgram", SqlDbType.Structured);
parameter.Value = serviceProgramDataTable;
parameter.TypeName = "dbo.ServicePrograms_UDT";
var parameter2 = new SqlParameter("@Fiscal_Period_Code", SqlDbType.NVarChar, 15);
parameter2.Value = Fiscal_Period_Code;
var parameter3 = new SqlParameter("@CreatedBy", SqlDbType.NVarChar, 50);
parameter3.Value = CreatedBy;
using (var context = new CRSContext())
{
context.Database.CommandTimeout = 360000;
var result = context.Database.SqlQuery<int>("usp_Upload_ServicePrograms @ServiceProgram, @Fiscal_Period_Code, @CreatedBy", parameter, parameter2, parameter3).FirstOrDefault();
return result;
}
}
It is failing for some reason, but the same Excel file I have exported into a Table, then creating a Table Variable of type (the User Defined Type) that I am using then inserting into that Table variable from the Table that I have Excel data in, then executing the Stored Procedure is not failing actually importing the Data as it is, I am not sure why the Stored Procedure executes but the above method fails, in both the cases Stored Procedure and Excel are the same. Here is how I am executing the Stored Procedure:
declare @ServiceProgram ServicePrograms_UDT
declare @fiscalPeriod nvarchar(15)='FY 2016-2017', @CreatedBy nvarchar(50)='aaleemmo'
insert into @ServiceProgram(ServiceCode, ProgramCode, UnitTypeDesc, RateCap, CountyCode)
select [service code], [Program Code], [Unit Type], [Rate Cap], [County Code] from SUDCRS..zzServiceProgramCountyExcelData
exec dbo.usp_Upload_ServicePrograms @ServiceProgram, @fiscalPeriod, @CreatedBy
And one more doubt I have is, when my WCF Service is posting this huge excel data as datatable to the Database, would it lose the Data when it is posting huge data, if it is losing that, is there any other approach I can execute this stored procedure.
Please let me know anything that's possible, a suggestion, a code snippet or even a tiny suggestion, any thing helps, its little bit urgent - please, thanks a lot.
|
|
|
|
|
DO NOT repost the same question over and over. You posted this in the QA forum 22 hours ago.
|
|
|
|
|
Sorry I thought these two are considered differently and I was not able to delete that one before posting here. I don't know, is there a way to delete QA posts, if there is can you please let me know how?
|
|
|
|
|
OK, thanks...
I`m failing to write to the data field, in the original Python code the method is GET and still i see data on the request data field but on the C# code I’m not sure how to get the same capture, im getting something like this, where my data (the commands to the remote system) been attached to the header:
GET /loadinst.cgi <EEX Ver='1.0'><CMD ....
Host: xxx.xxx.xxx.148
Accept-Encoding: identity
and the data field is empty, so the remote instrument refuse the connection.
So my question is what is the C# implementation to get something like this:
Hypertext Transfer Protocol
GET /loadinst.cgi HTTP/1.1\r\n
Host: xxx.xxx.xxx.148\r\n
Accept-Encoding: identity\r\n
Content-Length: 119\r\n
\r\n
[Full request URI: http:
[HTTP request 1/1]
[Response in frame: 30]
File Data: 119 bytes
Data (119 bytes)
Data: <EEX Ver='1.0'><CMD...
[Length: 119]
thanks for the help...
|
|
|
|
|
Uhhh...I think you posted this reply to the wrong thread. It has nothing to do with the question that was asked.
|
|
|
|
|
Sorry.. posted in the wrong place...
|
|
|
|
|
Yeah I haven't got any reply in both the forums buddy, any help my friend?
|
|
|
|
|
Nope. I don't use UDTs let alone use them with EF.
|
|
|
|
|
Is that a bad Combination buddy?
|
|
|
|
|
|
am using this code inside insert method
Insert into table (startdate) values (DateTime.ParseExact(Startdate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture))
i have textbox and want to insert null value
|
|
|
|
|
There are a couple of things here:
1) Text boxes don't contain NULL values - they can contain empty strings, but that is a very different thing.
2) ParseExact will fail if the string doesn't match - which means you must either use a try...catch block, or better use TryParseExact instead, reporting a problem to the user instead of trying to pass anything to the DB.
3) What you show won't work: even if it did what you think, it would pass the string version to SQL via concatenation, and that really should be avoided as it makes SQL convert the string back to a DateTime and that can introduce errors.
So verify the TB at the start of the method, and pass DateTime or NULL like this:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (startDate) VALUES (@SD)", con))
{
object o;
if (string.IsNullOrWhitespace(Startdate.text)) o = DbNull.Value;
else o = valueConvertedToDateTimeEarilerWhenYouValidatedIt;
cmd.Parameters.AddWithValue("@SD", o);
cmd.ExecuteNonQuery();
}
}
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have 8000 records i want put server side pagination and search
|
|
|
|
|
|
|
Hi Ann - welcome to the site!
Unfortunately, "teach me some of your knowledge" isn't really something we can do in a little text box - we have no idea what you do or don't know and understand, and the last thing we want to do is send you off in a direction that your course isn't taking yet. And I'm sure you are already aware that there isn't "one way to do it" but pretty much as many different ways as there are developers to try it!
So you need to be rather more specific about exactly what you are trying to do, what you have tried, what happened when you tried, where you are stuck, and what help you need! I know, I know - that sounds like a lot, but we can't see your screen, access your HDD, or read your mind: we only get exactly what you type to work with. And when you post the computer equivalent of phoning the garage, saying "it broke" and ending the call we get nothing to really work with!
So think about what you are having difficulty with and try explaining in good detail - the better your questions, the better our answers!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
|
Thanks; is the beer in the post?
|
|
|
|
|
how can I implement the cd funtion?
|
|
|
|
|
If you're using the FtpWebRequest class, you have to "fake" it by adding the directory to the URL:
Changing to the root directory with FtpWebRequest – Mariya Atanasova's Blog[^]
If you're using something else, then you'll need to tell us what you're using, as the answer will likely be different for each FTP client library.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to make a windows notifyicon program that automatically returns answers to a question that i copied in c# winforms. How can i make that?
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
This is not a good question: we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Teun van den Broek wrote: How can i make that? By writing a lot of code. I'm not really sure what kind of answer you are looking for.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
If you have to ask, "How do I write an entire program?", you've got a much bigger problem with your skill set. You need to break the application down into smaller and smaller solvable chunks.
You said you have to display a notify icon. OK, so do you know how to display a notify icon on the Task Bar?
Do you know how to interact with the notify icon when someone clicks on it?
Know how to handle a dialog and text box?
No? You've got a lot of research to do.
|
|
|
|
|