The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> .Net Development
|
C# web service that can't remember values.
Discuss C# web service that can't remember values. in the .Net Development forum on Dev Shed. C# web service that can't remember values. .NET development forum discussing all .NET derivatives including C#, VB.NET, ASP.NET, ADO.NET and more. Learn the ins and outs of using the .NET framework.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 4th, 2003, 05:59 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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;
}
|

July 4th, 2003, 06:47 PM
|
|
Contributing User
|
|
Join Date: Jun 2003
Location: Portugal
Posts: 106
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 10
|
|
in the server side(web service) replace line 1 with this:
Code:
private static string l_message = "";
that should work
|

July 4th, 2003, 07:10 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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).
|

July 4th, 2003, 07:16 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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!
|

July 4th, 2003, 07:22 PM
|
|
Contributing User
|
|
Join Date: Jun 2003
Location: Portugal
Posts: 106
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 10
|
|
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# 
|

July 4th, 2003, 07:41 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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
|

July 4th, 2003, 07:42 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
This is the reference:
|

July 4th, 2003, 08:14 PM
|
|
Contributing User
|
|
Join Date: Jun 2003
Location: Portugal
Posts: 106
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 10
|
|
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();
|

July 4th, 2003, 09:26 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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.
|

July 4th, 2003, 09:38 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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. 
|

July 4th, 2003, 10:01 PM
|
|
Contributing User
|
|
Join Date: Jun 2003
Location: Portugal
Posts: 106
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 10
|
|
Quote:
SqlDataReader sdr;
It didn't like it. I'll try it again. |
Did u forget to put: using System.Data.SqlClient; ?
|

July 4th, 2003, 10:42 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
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.
|

July 4th, 2003, 10:56 PM
|
|
Contributing User
|
|
Join Date: Jun 2003
Location: Portugal
Posts: 106
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 10
|
|
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
|

July 4th, 2003, 11:01 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 24
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
100%
Have a good night. 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|