相关文章推荐
开朗的打火机  ·  AI赋能电商 ...·  1 周前    · 
傻傻的南瓜  ·  java - is there a way ...·  1 年前    · 
英俊的大葱  ·  python - SVG ...·  1 年前    · 
I need help with the project I am currently working on. Please bare with me, I'm not good at coding specially with c# this is my first attempt.
I have a button the will pull the data from webservice. Saving of data to database will be triggered with the same button. I have manage to display the string via tutorial and now stuck on saving I don't know where I went wrong it keeps on throwing error that **Value cannot be null ** I have provided the error message for your reference and the json output.
Json output:
[ { " NAME" : " FOLDER_NAME" , " LOW" : " 0000000376_0000000385" , " HIGH" : " SAMPLE\\376_AGENPATH\\385_NAMEPATH, INC" , " ERDAT" : " 0000-00-00" , " AEDAT" : " 0000-00-00" }]
Error Message:
Quote:
System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: source Source=System.Core
StackTrace: at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) at SAPSO.CIP.ProcessOutput(DateTime start, DateTime end) in C:\prjname\fldername\GET\SAPSO\CIP.cs:line 58 at SAPSO.Form1.m_oWorker_DoWork(Object sender, DoWorkEventArgs e) in C:\prjname\fldername\GET\SAPSO\Form1.cs:line 103 at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
This exception was originally thrown at this call stack: [External Code] SAPSO.CIP.ProcessOutput(System.DateTime, System.DateTime) in CIP.cs SAPSO.Form1.m_oWorker_DoWork(object, System.ComponentModel.DoWorkEventArgs) in Form1.cs

What I have tried:
This is my CIP.cs
public string NAME { get ; set ; } public string HIGH { get ; set ; } public string LOW { get ; set ; } public DateTime ERDAT { get ; set ; } public DateTime AEDAT { get ; set ; } RestClient client; RestRequest request; public CIP () client = new RestClient( @" http://privateurl:8000/" ); client.Authenticator = new HttpBasicAuthenticator( " user" , " pass" ); public List<CIPOutput> GetCIPOutputs(DateTime start, DateTime end) request = new RestRequest( " sap/ez/zcip" , Method.Get); request.AddParameter( " sap-client" , " 200" ); request.AddParameter( " start" , " " ); request.AddParameter( " end" , end.ToString( " yyyyMMdd" )); var output = client.ExecuteAsync<List<CIPOutput>>(request); var o = output.Result.Data; return o; public void ProcessOutput(DateTime start, DateTime end) var output = GetCIPOutputs(start, end); if (output == null || output.Count < 1 ) Console.WriteLine( " Null" ); Console.WriteLine(output.ToString()); var xmlPath = new XElement( " CIPS" , from CIPPath in output select new XElement( " CIP" , new XElement( " NAME" , CIPPath.NAME), new XElement( " HIGH" , CIPPath.HIGH), new XElement( " LOW" , CIPPath.LOW), new XElement( " ERDAT" , CIPPath.ERDAT), new XElement( " AEDAT" , CIPPath.AEDAT) insertCIP(xmlPath.ToString(), " InsertCIPpath" ); // insert to db int insertCIP( string xml, string strdproc) int row = 0 ; using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ " BMSSAP" ].ConnectionString)) using (SqlCommand cmd = new SqlCommand(strdproc)) cmd.Connection = con; cmd.CommandTimeout = 3000 ; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue( " @xmldata" , xml); con.Open(); row = cmd.ExecuteNonQuery(); con.Close(); catch (Exception ex) Console.WriteLine(ex.Message); return row; And this is how i call the function in my form1.cs
void m_oWorker_DoWork( object sender, DoWorkEventArgs e) _backgroundWorkerThread = Thread.CurrentThread; SAP svc = new SAP(); CIP cip = new CIP(); cip.ProcessOutput(dte_from.Value, dte_to.Value); catch (ThreadAbortException) e.Cancel = true ; m_oWorker.Dispose(); Thread.ResetAbort(); We can't tell - we would need your data and your code running to even being looking and we have no idea what that looks like.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •