Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Dromio
Oct 16, 2002
Sleeper

havelock posted:

You can keep using WebRequest. I believe there's a Credentials property off of request that you can add stuff to. new NetworkCredentials (UsernamePasswordCredentials?) or something like that.

For the record, this does not work. That'll work for Windows Authentication, but not Forms Authentication.

I ended up doing some "scraping" code-- getting the logon form for the viewstate, posting back to it with the login/password, then getting the authentication cookie from that response.

Adbot
ADBOT LOVES YOU

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
This is a bit of a longshot but I am trying to connect to a SQL Server 2000 database and fill a dataset with some tables. I am either getting a 'Internal Fatal Connection Error' or a timeout, and which one seems dependent on the table I'm querying.

Conversely if I do select * from table and execute a data reader it works. Does anyone have any clue what I might have made an error in or what is causing the internal error?

Here is the connection string

databaseConnection.ConnectionString = "Data Source=xxx.xxx.xx.xx,xxxxx;Network Library=DBMSSOCN;Initial Catalog=xxx;User ID=xxxx;Password=xxxxxxxxxxx; Trusted_Connection=False";

Here's the SqlCommand

SqlCommand sqlCommand = new SqlCommand("", databaseConnection);

Here's the fill code

DataAdapter.SelectCommand = sqlCommand;
DataAdapter.SelectCommand.CommandText = "SELECT * FROM tbl1";
DataAdapter.Fill(CommonVariables.DataStorage);

edit: I'm trying to pull about 2k records. I've tried setting the time out for 600 seconds, attaching the database on my local machine. Not having any success. Smaller tables (200 records or less) are handled ok.

Nurbs fucked around with this message at 19:55 on Jun 11, 2007

wwb
Aug 17, 2004

Stramit posted:

I have been developing an application for university over the past few weeks, it's a system with a database back-end and has been fully developed and ready for deployment over IIS.

This is where the problems began for me. During the development phase I was using a .mdf file located in the App_Data folder of the web application for the database. This has been working quite well, but when I deploy the site to IIS it seems like the application can not bind to SQL Server Express properly. And from my playing around (Last 1/2 a day or so) I think it has to do with the permissions in SQL Server.

This is the connection string I am using (this does work locally):
code:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Restaurant.mdf;DataBase=NewRes;Trusted_Connection=Yes;
User Instance=False
And the exception I get when attempting to run the application over IIS:

code:
NHibernate.ADOException: cannot open connection ---> System.Data.SqlClient.SqlException: 
CREATE DATABASE permission denied in database 'master'.
I have checked the permissions on the App_Data on the IIS server and have granted the following users full access: ASPNET, NETWORK, NETWORK SERVICE. Am I missing any or is my SQL express just not configured right? I'm not an Microsoft SQL / IIS genius, and any help would be appreciated.

edit: Ubreaking tables

I don't use Sql express, but I think changing the User Instance parameter to true will fix things.

wwb
Aug 17, 2004

Nurbs posted:

This is a bit of a longshot but I am trying to connect to a SQL Server 2000 database and fill a dataset with some tables. I am either getting a 'Internal Fatal Connection Error' or a timeout, and which one seems dependent on the table I'm querying.

Conversely if I do select * from table and execute a data reader it works. Does anyone have any clue what I might have made an error in or what is causing the internal error?

Here is the connection string

databaseConnection.ConnectionString = "Data Source=xxx.xxx.xx.xx,xxxxx;Network Library=DBMSSOCN;Initial Catalog=xxx;User ID=xxxx;Password=xxxxxxxxxxx; Trusted_Connection=False";

Here's the SqlCommand

SqlCommand sqlCommand = new SqlCommand("", databaseConnection);

Here's the fill code

DataAdapter.SelectCommand = sqlCommand;
DataAdapter.SelectCommand.CommandText = "SELECT * FROM tbl1";
DataAdapter.Fill(CommonVariables.DataStorage);

edit: I'm trying to pull about 2k records. I've tried setting the time out for 600 seconds, attaching the database on my local machine. Not having any success. Smaller tables (200 records or less) are handled ok.

Try selecting the top 10 or 100 records and see if the problem persists. And is there any reason why you are forcing a TCP/IP connection?

Verve
Nov 19, 2005
How do you set the main form in C# using Visual Studio ?

Say I have 2 forms, form A and form B. Currently the default main form is form A and I wish to change it to form B instead. How do I do this ?

csammis
Aug 26, 2003

Mental Institution

Verve posted:

How do you set the main form in C# using Visual Studio ?

Say I have 2 forms, form A and form B. Currently the default main form is form A and I wish to change it to form B instead. How do I do this ?

Open Program.cs, and where the line:

code:
Application.Run(new FormA());
appears, change it to FormB

Fryedegg
Jan 13, 2004
Everquest killed my libido (and my cat). 8(

Verve posted:

How do you set the main form in C# using Visual Studio ?

Say I have 2 forms, form A and form B. Currently the default main form is form A and I wish to change it to form B instead. How do I do this ?

By main form, are you referring to the Start Page? If so, just right click on it in the solution explorer, and select "Set As Start Page".

Edit: totally missed that one, I guess.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe
I am in some need of help for SQL related stuff. I think I mentioned before that I'm a huge SQL newbie, so bear with me :(.

I need to accomplish the following things:

1. Connect to my database.
2. Insert a row of blank data in the main table, obtain the value of the primary key of the row I just inserted, then assign that value to an instance variable.
3. Update the main table with information from an .xml document.
4. Upload files into the DB.

My company previously wanted me to create a ASP.NET/C# code behind website to accomplish all this, in which SQLDataSource worked absolutely wonderfully for (to transfer data from the .xml document to the necessary tables, not for transferring files). But since they scratched that, I now have to create a C# console program that would essentially do the same thing.

Upon looking at the MSDN, I discovered a jumble of potential classes to use, in which I'm not even sure where to start with. It's been recommended to use a SQLDataAdapter and a DataSet to connect and modify the database, but I think logically, it would take more time since all I'm doing is simply transferring information from an .xml to SQL tables, then transferring files.

What's the easiest and most elegant way to accomplish this? Recommend me a way to start, as I'm really not sure exactly how to go about this. I've been reading Programming C# by Jesse Liberty (the O'Reilly series), but it shows a very basic example of messing around with SQL DB's. Anyone know of good guides for this?

Thanks as always!

wwb
Aug 17, 2004

First--forget about datasets, and data adapters, and DataSourceControls. This is a job for plain old SqlConnections, SqlCommands and DbTransactions. Not quite in a code writing mood, but I will try and steer you in the right direction:

1) Use the SqlConnection to create connections.
2) You probably want to combine this and #3 into one command, no need to hit the DB twice. The best way to do this in general is to use an output parameter to capture the value of the sql SCOPE_IDENTITY() function. Something like:
code:
SqlConnection conn=getConnection(); //#1
SqlCommand cmd=conn.CreateCommand();
DataObject do=GetDataFromXml(xml); //gets the data from the xml and loads it into an object for easy access.
cmd.CommandType=CommandType.Text;
cmd.CommandText="INSERT INTO Foo (ColA, ColB) VALUES (@ColA, @ColB); SET @IdOut=SCOPE_IDENTITY";
cmd.Parameters.AddWithValue("@ColA", do.ColA);
cmd.Parameters.AddWithValue("@ColB", do.ColB);
SqlParameter idOut=cmd.Parameters.Add("@idOut");
idOut.Type=SqlDataType.Int //presumes INT IDENTITY; change as appropriate
idOut.Length=4 //see above, INT is length 4
idOut.Direction=ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery(); //execute the command
int id=(int)idOut.Value; //get the parameter value
conn.Close();
Note--code typed into forum text box, not visual studio. It is meant as guidance and is not necessarily perfect.

4) You can use similar methods to upload files. Just read them into a byte[] and use a parameterized statement to INSERT them, capturing an ID like above.

One other note--you might want to run this entire operation, or at least individual iterations, within a DbTransaction. This means that if something fails, the whole kit and caboodle will get rolled back.

Hope this helps.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
And now, to the GUI portion of our competition. Two quickies involving win forms:

I have a ContolSet control with a Fixed3D border. However, the normal 3D border makes the control look sunket; I want to make the control look raised. Basically, I need to invert the shadows and the hilights. Is there any (easy) way to do this?

Also, I have a ListView embedded in said ControlSet. I have this ListView anchored in all four directions, however at a certain size (namely, when the window is sized too small to see the ListView at all) I want to the ListView to stop resizing and just hold its height, wherein the ControlSet's auto-scroll property should kick in. I tried setting the MinimumSize property of the ListView, but it doesn't seem to have any effect. I know I could probably do this by hooking OnResize and computing it manuall, but is there an easier way?

SLOSifl
Aug 10, 2002


Magicmat posted:

And now, to the GUI portion of our competition. Two quickies involving win forms:

I have a ContolSet control with a Fixed3D border. However, the normal 3D border makes the control look sunket; I want to make the control look raised. Basically, I need to invert the shadows and the hilights. Is there any (easy) way to do this?
Override OnPaintBackground and use the static ControlPaint.DrawBorder3D method to draw the border. You can probably leave the base.OnPaintBackground(e) call in there to ensure the rest of the control looks normal.

quote:

Also, I have a ListView embedded in said ControlSet. I have this ListView anchored in all four directions, however at a certain size (namely, when the window is sized too small to see the ListView at all) I want to the ListView to stop resizing and just hold its height, wherein the ControlSet's auto-scroll property should kick in. I tried setting the MinimumSize property of the ListView, but it doesn't seem to have any effect. I know I could probably do this by hooking OnResize and computing it manuall, but is there an easier way?
Set the AutoScrollMinSize property set on the scrollable control.

Also, what is a ControlSet control? I'm assuming that it's a custom control, hence the override suggestion above. If it's sealed or you can't override it, you can use the Paint event.

SLOSifl fucked around with this message at 17:47 on Jun 14, 2007

MillDaKill
Aug 19, 2003

How could you Carl?
This has probably already been asked but searching does not seem to work right now. In VB.net what does dim stand for? I have heard dimension but that does not make any sense to me.

SLOSifl
Aug 10, 2002


It's dimension. It means something along the lines of "allocate space (dimension) in memory for this variable". I don't think you'll get much more of an answer than that though.

edit:
These seem reasonable:

Dictionary.com posted:

Dimension
verb
1. indicate the dimensions on; "These techniques permit us to dimension the human heart"
2. shape or form to required dimensions

SLOSifl fucked around with this message at 18:32 on Jun 14, 2007

Dromio
Oct 16, 2002
Sleeper
This is a real long-shot, but I'm always amazed by how how drat smart folks in this thread are, so maybe someone can help me.

I'm using Index Server for full-text searches on dynamically generated site(s) on the server. I've got a management console that creates the site and automatically creates the index server catalog as well.

I'm using a combination of the CIODMLib COM interface and registry
manipulation to automatically create the catalogs. When my code is done,
you can use the index server manager plugin to see that the catalog exists in Index
Server, the proper directory is added, and the "Generate Abstracts"
checkbox is checked. Here's some sample code:

code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using CIODMLib;

namespace Manager
{
    static class CatalogCreator
    {
        public static void CreateCatalog(string CatalogName, string
SiteName, string IndexPath, string RootPath)
        {
            AdminIndexServerClass Admin = new AdminIndexServerClass();
            Admin.Stop();
            if (!System.IO.Directory.Exists(IndexPath))
            {
                System.IO.Directory.CreateDirectory(IndexPath);
            }
            ICatAdm AddedCatalog =
(ICatAdm)Admin.AddCatalog(CatalogName, IndexPath);

            SetRegWord(CatalogName);

            AddedCatalog.AddScope(RootPath, false, null, null);

            Admin.Start();
        }

        private static void SetRegWord(string CatalogName)
        {
            RegistryKey CatalogKey =
Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control
\ContentIndex\Catalogs\" + CatalogName,
RegistryKeyPermissionCheck.ReadWriteSubTree,
System.Security.AccessControl.RegistryRights.SetValue);
            CatalogKey.SetValue("GenerateCharacterization", 1,
RegistryValueKind.DWord);
        }
    }

}
This all LOOKS fine, but the results from the index do not contain
characterizations(abstracts). Am I missing something critical? Has
anyone else managed to do this?

Edit: And again struggle for days, break-down and post the question, then figure it out on my own minutes later.

I needed to set additional registry entries: FilterFilesWithUnknownExtensions and MaxCharacterization.

Dromio fucked around with this message at 21:40 on Jun 14, 2007

fankey
Aug 31, 2001

I'm have some questions about serialization that I hope someone can help me with. I wrote a little program to test out different serialization techniques which raised some questions. I'm basically saving a class which contains a int. The first thing I noticed is that each instance of my class has a built in overhead of 14 bytes - is that normal? I there a way to decrease that? The second issue is that if I implement ISerializable it's slower both serializing and deserializing. I can't imaging I'm doing anything too different than what the built in serialization engine does but obviously that's the case.

Here's the output I get
code:
testing csharp_testbed.MyInt...
  - writing took 551ms
  - reading took 1044ms
  - size is 1800378 ( 18 per object )
testing csharp_testbed.MyInt2...
  - writing took 654ms
  - reading took 1158ms
  - size is 2200392 ( 22 per object )
testing csharp_testbed.MyInt3...
  - writing took 693ms
  - reading took 1405ms
  - size is 1800381 ( 18 per object )
from this source
code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;


namespace csharp_testbed
{
  [Serializable]
  public class MyInt
  {
    int _value;
  }

  [Serializable]
  public class MyInt2
  {
    int _value;
    int _value2;
  }


  [Serializable]
  public class MyInt3 : ISerializable
  {
    int _value = 0;
    public MyInt3()
    {
    }
    public MyInt3(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
    {
      _value = info.GetInt32("value");
    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
      info.AddValue("value", _value);
    }
  }

  public class color_test
  {
    static void test<T>() where T : class, new() 
    {
      Console.WriteLine("testing {0}...", typeof(T));
      string file_name = typeof(T).ToString() + ".dat";
      List<T> list = new List<T>();
      for (int i = 0; i < 100000; i++)
      {
        list.Add(new T());
      }
      System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
      st.Start();
      BinaryFormatter bf = new BinaryFormatter();
      using (FileStream fs = new FileStream(file_name, FileMode.Create, FileAccess.Write, FileShare.None))
      {
        bf.Serialize(fs, list);
      }
      st.Stop();
      Console.WriteLine("  - writing took {0}ms", st.ElapsedMilliseconds);
      // load
      st.Reset();
      st.Start();
      IFormatter formatter = new BinaryFormatter();
      using (FileStream stream = new FileStream(file_name, FileMode.Open, FileAccess.Read))
      {
        List<T> new_list = (List<T>)(formatter.Deserialize(stream));
      }
      st.Stop();
      Console.WriteLine("  - reading took {0}ms", st.ElapsedMilliseconds);

      FileInfo fi = new FileInfo(file_name);
      Console.WriteLine("  - size is {0} ( {1} per object )", fi.Length, fi.Length/list.Count);
    }
    static void Main(string[] args)
    {
      try
      {
        test<MyInt>();
        test<MyInt2>();
        test<MyInt3>();
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex);
      }

    }
  }
}

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

SLOSifl posted:

Override OnPaintBackground and use the static ControlPaint.DrawBorder3D method to draw the border. You can probably leave the base.OnPaintBackground(e) call in there to ensure the rest of the control looks normal.
Set the AutoScrollMinSize property set on the scrollable control.

Also, what is a ControlSet control? I'm assuming that it's a custom control, hence the override suggestion above. If it's sealed or you can't override it, you can use the Paint event.


That method for 3D borders works great! Except that it also draws the border of all containers within the control as having the same "raised" border. For example, I have a table layout control in my custom control, and it, too, gets a 3D border, even with its boeder set to "none" in the designer, which I don't want. Is there any way to get around that?

uXs
May 3, 2005

Mark it zero!

Stramit posted:

This is the connection string I am using (this does work locally):
code:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Restaurant.mdf;DataBase=NewRes;Trusted_Connection=Yes;
User Instance=False
...

I have checked the permissions on the App_Data on the IIS server and have granted the following users full access: ASPNET, NETWORK, NETWORK SERVICE. Am I missing any or is my SQL express just not configured right? I'm not an Microsoft SQL / IIS genius, and any help would be appreciated.

edit: Ubreaking tables

That AttachDBFilename thing in your connection string looked suspicious to me, so I went to check http://www.connectionstrings.com/?carrier=sqlserver2005. According to that page, the AttachDBFilename=whatever option only works for local SQL servers. So if you have seperate machines for IIS and SQL server (as I suppose you do), your connection string will not work.

From your error message, it looks like you're using the .NET sqlconnection, so your connectionstring should probably be something like: "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;"

Shayla
Nov 4, 2004
This is a little awkward, but I have a database I need to get to PocketPC. My supervisor wants me to write a C# dll to serialize the needed tables, and modify the vb6 PocketPC application to receive the table data serialized by C# and run SQL queries on it. As far as I can tell, there is no easy way to do this. .NET doesn't do DAO (to my knowledge,) and vb6 doesn't do ADO.NET (obviously.)

I was thinking about using vb6 to create the dll and SOAP to transfer the data. Any ideas?

Edit: Nevermind. Turns out we're rewriting the PocketPC application to .NET. Fun.

Shayla fucked around with this message at 16:28 on Jun 18, 2007

wwb
Aug 17, 2004

^^^^^Ever consider Sql Mobile--it is made for scenarios such as this.

SLOSifl
Aug 10, 2002


Magicmat posted:

That method for 3D borders works great! Except that it also draws the border of all containers within the control as having the same "raised" border. For example, I have a table layout control in my custom control, and it, too, gets a 3D border, even with its boeder set to "none" in the designer, which I don't want. Is there any way to get around that?
I didn't know it would do that. Maybe override OnPaint instead? Or use the Paint event rather than overriding anything?

MrBishop
Sep 30, 2006

I see what you did there...

Soiled Meat
Not really a programming question, but I could use a recommendation on a charting package for .Net. Our immediate need is for ASP.NET charting, but I can foresee us using charts in Windows Forms down the road, so a package containing both ASP and Windows Forms components is desirable.

It seems like there are a lot of offerings, so I'm looking for some input with regard to what you may have experience with, positive or negative.

genki
Nov 12, 2003

MrBishop posted:

Not really a programming question, but I could use a recommendation on a charting package for .Net. Our immediate need is for ASP.NET charting, but I can foresee us using charts in Windows Forms down the road, so a package containing both ASP and Windows Forms components is desirable.

It seems like there are a lot of offerings, so I'm looking for some input with regard to what you may have experience with, positive or negative.
We're using http://www.componentone.com/ and it seems to be doing the job ok... I don't work with that part of the app though, so I don't really know all the features or anything.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



These guys seem pretty competant: http://www.devexpress.com/Products/NET/WinForms/XtraCharts/

We dont use the charts but we do use some of their other products. Plus their charts look nice and work in ASP.NET.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
I'll probably figure this out on my own like last time as soon as I post the thread but I'm kind of stuck.

I want to bind a datasource with a combobox and then force the combobox to drop down and show what is in the table I just bound to it (basically I'm feeding the results of a search into the combobox).

I can't figure out how to get the drop down event to fire. Doing combobox.dropdown() generates a syntax error.

Ch00k
Feb 18, 2004
Chicken

Nurbs posted:

I can't figure out how to get the drop down event to fire. Doing combobox.dropdown() generates a syntax error.
combobox.DroppedDown = true;

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Ch00k posted:

combobox.DroppedDown = true;

Thanks!

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

wwb posted:

First--forget about datasets, and data adapters, and DataSourceControls. This is a job for plain old SqlConnections, SqlCommands and DbTransactions. Not quite in a code writing mood, but I will try and steer you in the right direction:

1) Use the SqlConnection to create connections.
2) You probably want to combine this and #3 into one command, no need to hit the DB twice. The best way to do this in general is to use an output parameter to capture the value of the sql SCOPE_IDENTITY() function. Something like:
code:
SqlConnection conn=getConnection(); //#1
SqlCommand cmd=conn.CreateCommand();
DataObject do=GetDataFromXml(xml); //gets the data from the xml and loads it into an object for easy access.
cmd.CommandType=CommandType.Text;
cmd.CommandText="INSERT INTO Foo (ColA, ColB) VALUES (@ColA, @ColB); SET @IdOut=SCOPE_IDENTITY";
cmd.Parameters.AddWithValue("@ColA", do.ColA);
cmd.Parameters.AddWithValue("@ColB", do.ColB);
SqlParameter idOut=cmd.Parameters.Add("@idOut");
idOut.Type=SqlDataType.Int //presumes INT IDENTITY; change as appropriate
idOut.Length=4 //see above, INT is length 4
idOut.Direction=ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery(); //execute the command
int id=(int)idOut.Value; //get the parameter value
conn.Close();
Note--code typed into forum text box, not visual studio. It is meant as guidance and is not necessarily perfect.

4) You can use similar methods to upload files. Just read them into a byte[] and use a parameterized statement to INSERT them, capturing an ID like above.

One other note--you might want to run this entire operation, or at least individual iterations, within a DbTransaction. This means that if something fails, the whole kit and caboodle will get rolled back.

Hope this helps.

Okay...I think I have something going now. Thanks a ton, I appreciate it!

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

SLOSifl posted:

I didn't know it would do that. Maybe override OnPaint instead? Or use the Paint event rather than overriding anything?
I tried setting an event on the OnPaint method, but still the same thing. I even tried filtering by sender, but the sender is always my control. It gets called once for each control on my control, an imagebox, a tablelayoutpanel and the control itself. I tried filtering by sender, but the sender is always my own custom control. I even put a message box in the event, and I can see the drat thing draw a new 3D border around each control.

There has to be a method for only drawing a border around the control as a whole. At the very least, I think I could get the control's size and always draw to that, but even then I'm drawing the border twice more than necessary.

Dromio
Oct 16, 2002
Sleeper
I end up doing this a lot of times, and keep thinking there must be an easier way. With the framework so big, maybe there is and I just don't know about it.

Does anyone know a simple way to convert an IEnumerable to a comma-seperated list in a string? Right now I'm doing something like the following:

code:
StringBuilder CSVOut = new StringBuilder();
if(ListIn.Count>0)
{
  CSVOut.Append(ListIn[0]);
  if(ListIn.Count>1)
  {
    foreach(int i=1;i<ListIn.Count;i++)
    {
      CSVOut.Append(","+ListIn[i]);
    }
  }
}
It seems there'd be a simpler way.

wwb
Aug 17, 2004

There is a more intelligent way--use xml for output.

Now, to ease things, one could it an array of strings and use the Join method. Now, that does not take care of quoting things intelligently.

Dromio
Oct 16, 2002
Sleeper
Aha, see I knew there was something simple I was missing and it was just too generic to google. String.Join is exactly what I wanted. I feel foolish. Thank you.

SLOSifl
Aug 10, 2002


Dromio posted:

I end up doing this a lot of times, and keep thinking there must be an easier way. With the framework so big, maybe there is and I just don't know about it.

Does anyone know a simple way to convert an IEnumerable to a comma-seperated list in a string? Right now I'm doing something like the following:
string.Join will do it with an array. List<T> has a ToArray() method.

edit: whoops, beaten. Forgot to refresh.

pukeduke
Nov 20, 2003

ĄGOOOOOOALLLLLLL!
I'm using ASP.NET 2.0 mobile controls, and I'd like to be able to set the width of a mobile:command control, but it doesn't seem to have that property. Is there any way to do this? I'm obviously using Format="button" because setting the width of a text link wouldn't make sense


Thanks!

Biscuit Hider
Apr 12, 2005

Biscuit Hider
Do any of you guys use NHibernate 1.2?

I'm having some serious issues with my latest application, and I'm at my wits end. When a user is in the application, it will be blazing fast for a random period of time. All of a sudden, it will slow to a crawl and a page request will take upwards of 20 seconds to show up. Later, it will be blazing fast again.

The ASP.Net session is stored in the database, and the NHibernate session is opened for the length of each request. We are aware that opening a session for the length of each request is an expensive operation, but the load it is causing on our servers so far is minimal, so I do not think this is the issue.

Everything else about our project is pretty much a standard NHibernate setup as per the NHibernate documentation.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

Magicmat posted:

I tried setting an event on the OnPaint method, but still the same thing. I even tried filtering by sender, but the sender is always my control. It gets called once for each control on my control, an imagebox, a tablelayoutpanel and the control itself. I tried filtering by sender, but the sender is always my own custom control. I even put a message box in the event, and I can see the drat thing draw a new 3D border around each control.

There has to be a method for only drawing a border around the control as a whole. At the very least, I think I could get the control's size and always draw to that, but even then I'm drawing the border twice more than necessary.
Sitting in bed last night, I figured out the answer to my own question. I override OnPaintBackground and then only draw the border if e.ClippingRectangle == this.ClientRectangle. That way, I only draw the border if the border OnPaintBackground is asking me to point is the border of the whole control.

Update: Further testing showed that with the above method, there was unpredictable behavior when resizing the control. Repainting when, for example, you were moving another window over your application worked fine, but resizing caused the background to flicker in and out. So, back to redrawing the border every time OnBackgroundPaint is called. If anybody knows of a better way, I'd love to hear it.

Edit2: My atrocious spelling may explain my explain my preponderance of bugs.

Magicmat fucked around with this message at 10:23 on Jun 22, 2007

Thecate
Aug 30, 2006

Look under 'T' for 'The Meownarch!!'
Hey all,

I'm having an issue dynamically creating LinkButtons. Here's what I'm trying to do:

I'm keeping track of what state my page is in with some static variable, nothing crazy about that. Based on that value, I want to Query a database and generate a list of LinkButtons based on the returned values during the OnLoad of a Table that exists in the page. I can query the data no problem, and I can create the TableRows, TableCells, and LinkButtons, but for some reason they are showing up the NEXT time the screen posts. I tried creating the buttons in the OnPreRender stage also, but then button.Click += EventHandler("Button_Clicked"); doesnt register the event handler anymore.

Also, when I click a button, I want it to change color indicating the selection, but this is also not happening until the NEXT time the page posts.

I know my problem is becasue the page_load stage is occuring BEFORE the "Button_Clicked" function code is handled. How the hell do I change the appearance of the buttons if I can't tell which button was pressed until AFTER the page_load stage?

oberonix
Feb 21, 2007
that's doctor oberonix to you

Thecate posted:

Hey all,

I'm having an issue dynamically creating LinkButtons. Here's what I'm trying to do:

I'm keeping track of what state my page is in with some static variable, nothing crazy about that. Based on that value, I want to Query a database and generate a list of LinkButtons based on the returned values during the OnLoad of a Table that exists in the page. I can query the data no problem, and I can create the TableRows, TableCells, and LinkButtons, but for some reason they are showing up the NEXT time the screen posts. I tried creating the buttons in the OnPreRender stage also, but then button.Click += EventHandler("Button_Clicked"); doesnt register the event handler anymore.

Also, when I click a button, I want it to change color indicating the selection, but this is also not happening until the NEXT time the page posts.

I know my problem is becasue the page_load stage is occuring BEFORE the "Button_Clicked" function code is handled. How the hell do I change the appearance of the buttons if I can't tell which button was pressed until AFTER the page_load stage?

You could update the display in the event handler maybe, that's about all I can offer without seeing more code.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
Hi folks,

I am pulling data from a database, loading it into a dataset and then pulling some of it out with a dataset[currentTable].Select(filterExpression) which returns an array of datarows.

What is the best way to bind this array of datarows to a datagridview? simply setting the datagridview.datasource = datarowarray doesn't quite do it.

Ideally I'd like the column headers to be mapped as well. Would prefer to write a function so I can make iterate through the columns and set their visibility.

wwb
Aug 17, 2004

Thecate posted:

Hey all,

I'm having an issue dynamically creating LinkButtons. Here's what I'm trying to do:

I'm keeping track of what state my page is in with some static variable, nothing crazy about that. Based on that value, I want to Query a database and generate a list of LinkButtons based on the returned values during the OnLoad of a Table that exists in the page. I can query the data no problem, and I can create the TableRows, TableCells, and LinkButtons, but for some reason they are showing up the NEXT time the screen posts. I tried creating the buttons in the OnPreRender stage also, but then button.Click += EventHandler("Button_Clicked"); doesnt register the event handler anymore.

Also, when I click a button, I want it to change color indicating the selection, but this is also not happening until the NEXT time the page posts.

I know my problem is becasue the page_load stage is occuring BEFORE the "Button_Clicked" function code is handled. How the hell do I change the appearance of the buttons if I can't tell which button was pressed until AFTER the page_load stage?

First, that static object will bite you in the rear end. Unless you want every single user sharing data, then it makes sense.

Not exactly sure what is going on here, but a better plan is to park your data in an appropriately backed object and then databind to that once you handle your events. It is alot cleaner and one need not gain a PHD in page lifecycles to make things work.

Adbot
ADBOT LOVES YOU

wwb
Aug 17, 2004

Nurbs posted:

Hi folks,

I am pulling data from a database, loading it into a dataset and then pulling some of it out with a dataset[currentTable].Select(filterExpression) which returns an array of datarows.

What is the best way to bind this array of datarows to a datagridview? simply setting the datagridview.datasource = datarowarray doesn't quite do it.

Ideally I'd like the column headers to be mapped as well. Would prefer to write a function so I can make iterate through the columns and set their visibility.

You are halfway there. You also probably need to call DataBind() after you set the datasource.

Insofar as column headers go, you would probably have to iterate through the results after the table is bound and match up columns. Of course, if you are not dynamically picking columns as well, you could just write them in the aspx code and call it a day.

  • Locked thread