#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep 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;
    		}
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Portugal
    Posts
    106
    Rep Power
    11
    in the server side(web service) replace line 1 with this:
    Code:
    private static string l_message = "";

    that should work
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    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).
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep 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!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Portugal
    Posts
    106
    Rep Power
    11
    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#
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    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
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    This is the reference:
    Attached Images
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Portugal
    Posts
    106
    Rep Power
    11
    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/de...lstudionet.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();
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    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/de...lstudionet.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.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep 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.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Portugal
    Posts
    106
    Rep Power
    11
    SqlDataReader sdr;

    It didn't like it. I'll try it again.
    Did u forget to put: using System.Data.SqlClient; ?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    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.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Portugal
    Posts
    106
    Rep Power
    11


    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
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    100%

    Have a good night.

IMN logo majestic logo threadwatch logo seochat tools logo