.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 4th, 2003, 05:59 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry C# web service that can't remember values.

Client side (Program)
Line 1: Dim Test As New D_WebReference.Service_D() 'Create reference to object
Line 2: Test.DoThis() 'Invoke this method.
Line 3: MsgBox(Test.Message) 'Display this properties value.


Server side (Web service)
Line 1: private string l_message = ""; //declare variable in the declarations.
Line 2:// Invoke this method. Give "l_message" a value.
Code:
		[WebMethod]
		public void DoThis()
		{
			l_message="Save this!";
		}

Line 3:// The property "Message" should return "l_message".
Code:
[WebMethod]
		public string Message()
		{
			return l_message;
		}

Reply With Quote
  #2  
Old July 4th, 2003, 06:47 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
in the server side(web service) replace line 1 with this:
Code:
private static string l_message = "";



that should work

Reply With Quote
  #3  
Old July 4th, 2003, 07:10 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by fetcher
in the server side(web service) replace line 1 with this:
Code:
private static string l_message = "";



that should work


Oh my god....... That worked!

for (int i; i < 100; i++)
{
System.Console.WriteLine ("Thank you!");
}



If I do the webservice in VB, then it's fine!. It didn't want to work in C# (I ported all my existing VB .NET services over to C# web services).

Reply With Quote
  #4  
Old July 4th, 2003, 07:16 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
One more question... have you ever worked with ADO Command objects?

I couldn't get the Command object to work in C#, so I created a DLL in VB that handles the execute of data to the database.

In VB .NET
Code:
                CMD.CommandText = SQL
                CMD.Execute()


Very simple. In C#, it wants some odd parameters (I believe a DataReader )


Thanks again for your help!

Reply With Quote
  #5  
Old July 4th, 2003, 07:22 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
I think it is asking for a datareader because C# is using ADO.NET not ADO. Yea I've worked with ADO when I coded with Visual Basic but since .NET came along I've always used ADO.NET..... Unless you have some kind of a weird reason I can't see why you are still using ADO with VB.NET or C#

Reply With Quote
  #6  
Old July 4th, 2003, 07:41 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by fetcher
I think it is asking for a datareader because C# is using ADO.NET not ADO. Yea I've worked with ADO when I coded with Visual Basic but since .NET came along I've always used ADO.NET..... Unless you have some kind of a weird reason I can't see why you are still using ADO with VB.NET or C#


So.. if I used the following syntax:

Code:
        Dim RSA As ADODB.Recordset = New ADODB.Recordset()

            RSA.Open("Select * From Facts Order By Title", User.ConnectionString, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

            Do While RSA.EOF = False
                ListBox1.Items.Add(RSA.Fields("Title").Value)
                RSA.MoveNext()
            Loop


It's wrong? What's better? Going through 4 layers of objects to get the data? I LOVE the ADO Recordset. It's light, fast, and ultra efficient. Perhaps I should I read up on ADO .NET

I never realized that this was the wrong way of doing things in .NET

Reply With Quote
  #7  
Old July 4th, 2003, 07:42 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is the reference:
Attached Images
File Type: gif ado.gif (16.0 KB, 447 views)

Reply With Quote
  #8  
Old July 4th, 2003, 08:14 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
It's not wrong but ADO.NET is a huge improvement from ADO. I don't know if it is as simple as ADO but it's pretty easy to learn and you don't go through 4 layers

Read that as a start
http://msdn.microsoft.com/library/d...alstudionet.asp

populating a listbox using ado.net (accessing sql server)

Code:
	SqlDataReader sdr;
	SqlConnection sc = new SqlConnection("Data Source=localhost;User ID=xxxx;password=xxxx;Initial Catalog = sample");
	sc.Open();

	SqlCommand cmd = new SqlCommand("select role from roles",sc);

	sdr = cmd.ExecuteReader();
	listBox1.Items.Clear();				
	do {
	     while (sdr.Read())
		listBox1.Items.Add(sdr.GetString(0));
	}while(sdr.NextResult());

	sc.Close();

Reply With Quote
  #9  
Old July 4th, 2003, 09:26 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by fetcher
It's not wrong but ADO.NET is a huge improvement from ADO. I don't know if it is as simple as ADO but it's pretty easy to learn and you don't go through 4 layers

Read that as a start
http://msdn.microsoft.com/library/d...alstudionet.asp

populating a listbox using ado.net (accessing sql server)

Code:
	SqlDataReader sdr;
	SqlConnection sc = new SqlConnection("Data Source=localhost;User ID=xxxx;password=xxxx;Initial Catalog = sample");
	sc.Open();

	SqlCommand cmd = new SqlCommand("select role from roles",sc);

	sdr = cmd.ExecuteReader();
	listBox1.Items.Clear();				
	do {
	     while (sdr.Read())
		listBox1.Items.Add(sdr.GetString(0));
	}while(sdr.NextResult());

	sc.Close();


Thanks. I did try that before

SqlDataReader sdr;

It didn't like it. I'll try it again.

Reply With Quote
  #10  
Old July 4th, 2003, 09:38 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I see that as backwards in certain ways. Instead of having one control (ADO Recordset), we now have the DataReader, SqlConnection, and SqlCommand.

No biggie. I've seen this before in different pieces of source code. Just thought it was the hard way of doing something so simple. If the ADO.NET way is the right way, I shall become an expert on it.

Reply With Quote
  #11  
Old July 4th, 2003, 10:01 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
Quote:
SqlDataReader sdr;

It didn't like it. I'll try it again.


Did u forget to put: using System.Data.SqlClient; ?

Reply With Quote
  #12  
Old July 4th, 2003, 10:42 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by fetcher
Did u forget to put: using System.Data.SqlClient; ?


Ha ha ha! No...

In fact, I know remember a lot about ADO .NET - I played around with it for a few months, and everything was too slow. Things would take seconds to do in ADO .NET and half that time in the old ADO.

At the top of my web service.

// SQL Goodies
using System.Data.SqlClient;

// Access Goodies
using System.Data.OleDb;

I'm not a complete C# newbie. I've been a hardcore Visual Basic programmer for many years, and I'm experimenting with other languages.

By the way, I like how you're very familiar with C#. I'm going to ask one more question (if you don't mind). What's the C# ADO .NET equivalency for this:

Code:
        Dim CMD As ADODB.Command = New ADODB.Command()
        Dim CONN As ADODB.Connection = New ADODB.Connection()

            'Connect to the database
            CONN.ConnectionString = ConnectionString
            CONN.Open()

            'Give the Command object an active connection.
            CMD.ActiveConnection = CONN

            'Execute
            CMD.CommandText = SQL
            CMD.Execute()


The CMD.Execute() is the money line.

Let's see if you can go 3 for 3 today.
I promise, this is the last question.

Last edited by VBGOD : July 4th, 2003 at 10:45 PM.

Reply With Quote
  #13  
Old July 4th, 2003, 10:56 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6


Code:
SqlConnection sc = new SqlConnection(ConnectionString);
sc.Open();
SqlCommand cmd = new SqlCommand(SQL,sc);
int rowsAffected = cmd.ExecuteNonQuery();



and you also have ExecuteReader and ExecuteScalar

and now I'm going to sleep

Later

Reply With Quote
  #14  
Old July 4th, 2003, 11:01 PM
VBGOD VBGOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 24 VBGOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
100%

Have a good night.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > C# web service that can't remember values.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump