I'm developing SQL Server Database and it's connected with c# app. Now I'm having a problem with saving data to database. Can you figure it out why? Thanks!
Web.Main Code
[SoapDocumentMethod("http://tempuri.org/Main", ParameterStyle = SoapParameterStyle.Wrapped, RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = SoapBindingUse.Literal)]
public DataSet Main(
[XmlElement(IsNullable = true)] int? A,
string B,
[XmlElement(IsNullable = true)] int? C,
string D,
string E,
string connstring)
{
return (DataSet) this.Invoke(nameof (Main), new object[41]
{
(object) A,
(object) B,
(object) C,
(object) D,
(object) E,
(object) connstring
})[0];
}
WebService.SaveChanges
public Result SaveChanges(
something model,
string username,
int status)
{
Result result = new Result();
string empty = string.Empty;
if (model.number >= 0)
empty = Convert.ToString(model.number);
DataSet dataSet = this.Main(model.M, model.N, model.O, model.P, status, new DateTime?(DateTime.Now), new DateTime?(), model.R, model.S, model.T, true, new DateTime?(DateTime.Now), new DateTime?(), new DateTime?(DateTime.Now), username, Configuration.ConnectionString);
if (!dataSet.Tables[0].Rows[0]["Error"].Equals((object) 0))
return result;
}
The method called Main has a single statement which returns the first element of the result of a call to this.Invoke.
The first parameter to Invoke is the name of the method you wish to call. That name is Main.
So Main is calling itself and passing the parameters it was called with. This would seem to be an infinite loop
It doesn't seem likely to me that this code would compile as you are trying to create an array with 41 elements but the initializer is only six elements long. I would expect the compiler to say
CS0847 An array initializer of length '41' is expected.
Can you explain a bit more about what you are trying to do as this doesn't seem to make any sense at al?. And it is not valid code.
It looks like you have an actual runtime Exception which means that you must have code that compiles. Can you create a small sample of code which anyone can run which demonstrates your problem?
Debug to see whether any of dataSet,Tables[0], Rows[0] ["Error"] is null.
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
The message "Object not set to instance of Object" means that you are trying to use an object which has not been initialized. That is, you either set it to null, or you never set it to anything at all. The runtime throwing a
NullReferenceException always means the same thing: you are trying to use a reference. The reference is not initialized (or it was initialized, but is no longer initialized).
None
0 Points
1 Post
Object reference not set to an instance of an object
Feb 27, 2019 02:06 PM|marymary|LINK
Hi!
I'm developing SQL Server Database and it's connected with c# app. Now I'm having a problem with saving data to database. Can you figure it out why? Thanks!
Web.Main Code
[SoapDocumentMethod("http://tempuri.org/Main", ParameterStyle = SoapParameterStyle.Wrapped, RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = SoapBindingUse.Literal)]
public DataSet Main(
[XmlElement(IsNullable = true)] int? A,
string B,
[XmlElement(IsNullable = true)] int? C,
string D,
string E,
string connstring)
{
return (DataSet) this.Invoke(nameof (Main), new object[41]
{
(object) A,
(object) B,
(object) C,
(object) D,
(object) E,
(object) connstring
})[0];
}
WebService.SaveChanges
public Result SaveChanges(
something model,
string username,
int status)
{
Result result = new Result();
string empty = string.Empty;
if (model.number >= 0)
empty = Convert.ToString(model.number);
DataSet dataSet = this.Main(model.M, model.N, model.O, model.P, status, new DateTime?(DateTime.Now), new DateTime?(), model.R, model.S, model.T, true, new DateTime?(DateTime.Now), new DateTime?(), new DateTime?(DateTime.Now), username, Configuration.ConnectionString);
if (!dataSet.Tables[0].Rows[0]["Error"].Equals((object) 0))
return result;
}
Stack Trace:
Participant
1660 Points
952 Posts
Re: Object reference not set to an instance of an object
Feb 27, 2019 09:30 PM|PaulTheSmith|LINK
I'm not really a SOAP person but I'll have a go.
The method called Main has a single statement which returns the first element of the result of a call to this.Invoke.
The first parameter to Invoke is the name of the method you wish to call. That name is Main.
So Main is calling itself and passing the parameters it was called with. This would seem to be an infinite loop
It doesn't seem likely to me that this code would compile as you are trying to create an array with 41 elements but the initializer is only six elements long. I would expect the compiler to say
CS0847 An array initializer of length '41' is expected.
Can you explain a bit more about what you are trying to do as this doesn't seem to make any sense at al?. And it is not valid code.
It looks like you have an actual runtime Exception which means that you must have code that compiles. Can you create a small sample of code which anyone can run which demonstrates your problem?
Contributor
3500 Points
1300 Posts
Re: Object reference not set to an instance of an object
Feb 28, 2019 07:16 AM|Ackerly Xu|LINK
Hi marymary,
The problem may be with your code
Debug to see whether any of dataSet,Tables[0], Rows[0] ["Error"] is null.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
20 Points
22 Posts
Re: Object reference not set to an instance of an object
Mar 05, 2019 04:53 AM|lingmaaki|LINK
The message "Object not set to instance of Object" means that you are trying to use an object which has not been initialized. That is, you either set it to null, or you never set it to anything at all. The runtime throwing a NullReferenceException always means the same thing: you are trying to use a reference. The reference is not initialized (or it was initialized, but is no longer initialized).