Click here to Skip to main content
15,889,116 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Remoting and events Pin
bwilhite28-Jan-08 14:04
bwilhite28-Jan-08 14:04 
GeneralRe: Remoting and events Pin
Joachim Kerschbaumer6-Feb-08 4:24
Joachim Kerschbaumer6-Feb-08 4:24 
GeneralRe: Remoting and events Pin
bwilhite6-Feb-08 10:10
bwilhite6-Feb-08 10:10 
Generalabout web services Pin
dSolariuM27-Jan-08 2:39
dSolariuM27-Jan-08 2:39 
GeneralRe: about web services Pin
Paul Conrad27-Jan-08 10:28
professionalPaul Conrad27-Jan-08 10:28 
GeneralRe: about web services Pin
pmarfleet27-Jan-08 12:04
pmarfleet27-Jan-08 12:04 
GeneralRe: about web services Pin
bwilhite28-Jan-08 3:21
bwilhite28-Jan-08 3:21 
GeneralTable Adapter Weirdness Pin
#realJSOP25-Jan-08 9:57
mve#realJSOP25-Jan-08 9:57 
This isn't about the database side of it - it's about the code that was generated.

In a web site, another developer used the table adapter wizard to create some queries. Here's one of the generated blocks of code (he's using a stored procedure in Scalar mode):

public virtual object InsertMyThing(string MyThing) 
{
	
	System.Data.SqlClient.SqlCommand command = this.CommandCollection[1];
	if ((MyThing == null)) 
	{
		command.Parameters[1].Value = System.DBNull.Value;
	}
	else 
	{
		command.Parameters[1].Value = ((string)(MyThing));
	}
	System.Data.ConnectionState previousConnectionState = command.Connection.State;
	if (((command.Connection.State & System.Data.ConnectionState.Open) != System.Data.ConnectionState.Open)) 
	{
		command.Connection.Open();
	}
	object returnValue;
	try 
	{
		returnValue = command.ExecuteScalar();
	}
	finally 
	{
		if ((previousConnectionState == System.Data.ConnectionState.Closed)) 
		{
			command.Connection.Close();
		}
	}
	if (((returnValue == null) || (returnValue.GetType() == typeof(System.DBNull)))) 
	{
		return null;
	}
	else 
	{
		return ((object)(returnValue));
	}
}


I recently added the same thing to a project I'm working on. Here's my code:

public virtual System.Nullable<int> InsertMyThing(string MyThing) 
{
	System.Data.SqlClient.SqlCommand command = this.CommandCollection[1];
	if ((MyThing == null)) 
	{
		command.Parameters[1].Value = System.DBNull.Value;
	}
	else 
	{
		command.Parameters[1].Value = ((string)(MyThing));
	}
	System.Data.ConnectionState previousConnectionState = command.Connection.State;
	if (((command.Connection.State & System.Data.ConnectionState.Open) != System.Data.ConnectionState.Open)) 
	{
		command.Connection.Open();
	}
	object returnValue;
	try 
	{
		returnValue = command.ExecuteScalar();
	}
	finally 
	{
		if ((previousConnectionState == System.Data.ConnectionState.Closed)) 
		{
			command.Connection.Close();
		}
	}
	if (((returnValue == null)  || (returnValue.GetType() == typeof(System.DBNull)))) 
	{
		return new System.Nullable<int>();
	}
	else 
	{
		return new System.Nullable<int>(((int)(returnValue)));
	}
}
</int></int></int>


When he calls his adapter function, he uses the following:

int id = Convert.ToInt32(adapter.InsertMyThing(MyThing));


When I try that with MY adapter function, I get an Invalid Cast exception.

If you haven't already noticed, the return type is different in my version of the function, yet we both used the adapter wizard to create the queries, and we're using the same database/stored procedures.

What's going on here?


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


GeneralRe: Table Adapter Weirdness Pin
Paul Conrad25-Jan-08 11:25
professionalPaul Conrad25-Jan-08 11:25 
GeneralRe: Table Adapter Weirdness Pin
#realJSOP25-Jan-08 11:38
mve#realJSOP25-Jan-08 11:38 
GeneralRe: Table Adapter Weirdness Pin
Paul Conrad26-Jan-08 7:21
professionalPaul Conrad26-Jan-08 7:21 
GeneralRe: Table Adapter Weirdness Pin
led mike28-Jan-08 6:40
led mike28-Jan-08 6:40 
GeneralRe-using Code Pin
#realJSOP25-Jan-08 5:09
mve#realJSOP25-Jan-08 5:09 
GeneralRe: Re-using Code Pin
Tristan Rhodes25-Jan-08 5:31
Tristan Rhodes25-Jan-08 5:31 
GeneralRe: Re-using Code Pin
#realJSOP25-Jan-08 5:50
mve#realJSOP25-Jan-08 5:50 
GeneralRe: Re-using Code Pin
Tristan Rhodes25-Jan-08 6:07
Tristan Rhodes25-Jan-08 6:07 
GeneralRe: Re-using Code Pin
led mike25-Jan-08 6:59
led mike25-Jan-08 6:59 
GeneralRe: Re-using Code Pin
Luc Pattyn25-Jan-08 7:29
sitebuilderLuc Pattyn25-Jan-08 7:29 
GeneralRe: Re-using Code Pin
led mike25-Jan-08 7:48
led mike25-Jan-08 7:48 
GeneralRe: Re-using Code Pin
Kschuler25-Jan-08 8:17
Kschuler25-Jan-08 8:17 
GeneralRe: Re-using Code Pin
#realJSOP25-Jan-08 9:47
mve#realJSOP25-Jan-08 9:47 
GeneralRe: Re-using Code Pin
TheGreatAndPowerfulOz21-Feb-08 9:10
TheGreatAndPowerfulOz21-Feb-08 9:10 
QuestionHow to read text present on a image Pin
harivinod25-Jan-08 2:39
harivinod25-Jan-08 2:39 
AnswerRe: How to read text present on a image - Cross-post, ignore Pin
Justin Perez25-Jan-08 3:33
Justin Perez25-Jan-08 3:33 
GeneralRe: How to read text present on a image - Cross-post, ignore Pin
Paul Conrad25-Jan-08 4:04
professionalPaul Conrad25-Jan-08 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.