|
Just a guess, but are you sure all of the characters in the name can be converted to int?
only two letters away from being an asset
|
|
|
|
|
How can a character in a name be converted to an int?
Anyway - this will handle it using the TryParse method, though I suspect you're going to spend most of your time in the else block.
int converted;
if(Int32.TryParse(arrayOfLastNames[i], out converted)
{
convertedLastName[i] = converted;
}
else
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Int32.Parse would work with char and not strings. i.e. (char)'A' will be converted to its ASCII equivalent but (string)"A" will not. You will need to get each character of the last name and then convert.
AFAIK .Net uses UTF8 encoding to store strings, probably that is the reason it is not working now.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Uggh...What was I thinking?! My fault guys..wrong question..I was thinking about the type of an ASCII code.
So, is there a way to convert all the string into an ASCII code? I was thinking of converting all of the string to ASCII code because I think it's a good way to do to sort using radix sort just like what i said above.
modified on Tuesday, September 1, 2009 3:40 PM
|
|
|
|
|
1. Why can't you use Array.Sort method?
2. AFAIK the number of recursions depend upon the maximum number digits in the numbers. Hence, if you have last names like MacGhilleseatheanaich[^], I wonder how many iterations it would take.
To convert string to ASCII equivalent, you can use following code:
System.Text.Encoding encASCII= System.Text.Encoding.ASCII;
Byte[] stringBytes = encASCII.GetBytes(yourString);
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
The reason why i can't use Array.Sort() is because we're trying to implement all that we discussed about file organization and data structure etc, and because we discussed some sorting algorithms we'll be implementing radix sort. If we were not obliged to use radix sort, I would be eager to use Array.Sort and finish the program easily.
|
|
|
|
|
They're already in ASCII.
But if you want to waste bits by using int (32 bits) rather that char (16 bit), you can cast the chars to ints.
foreach ( char ch in s )
{
int i = (int) ch ;
...
}
|
|
|
|
|
Hi Everyone,
I have a "one to many" sort of situation. I am using a Key to get subset data. I started out using a class like this:
<code>
public class Contract
{
public int ContractID {get;set;}
public int CustomerID {get;set;}
public string CustomerName {get;set;}
public string Organization {get;set;}
public int TermsID {get;}
}
public class ContractDataMapper
{
public static List<Contract> GetContractData(int contractID)
{
List<Contract> returnValue = new List<Contract>();
...
while(reader.Read())
{
Contract contract = new Contract();
contract.CustomerID = Convert.ToInt32(reader["CustomerID"]);
contract.CustomerName = reader["CustomerName"].ToString();
...
if(!returnValue.Contains(contract))
returnValue.Add(contract);
}
reader.Close();
command.Dispose();
return returnValue();
}
}
</code>
But I soon realized that this is bad because I had to check to see if this ContractID has any TermsID associated with it and the way it currently is I would have to do something like:
if(ContractDataMapper.GetContractData(1234)[0].TermsID > 0)
Ideally I should have one class Contract and have other properties in a subclass. Now my question is ... do you think it would be better to have a struct or a subclass or something else?
Contract contract = new Contract(1234);
List<SubsetData> subset = contract.SubsetData;
I would appreciate your help.
|
|
|
|
|
|
using Automation (SHDocVw, MSHTML or something else?) or a WebBrowser control:
1)Is it possible to interrogate a flash control to discover its elements? For example, http://demo.garanti.com.tr/bireysel_demo/main.html[^], there are flash buttons. Can I determine there "ID"s?
2)Given the "ID" names of elements in a flash control, is it possible to click and/or select them?
|
|
|
|
|
New to C# - long time cobol programmer....
How do you define a db connection so it can be used across several windows forms?
I have the connection working but I have to establish the connection in each form.
iDB2Connection cn = new iDB2Connection();
cn.ConnectionString = "DataSource=" + txtiSeries.Text.Trim(' ')
+ ";DefaultCollection=" + txtDataLibrary.Text.Trim(' ')
+ "; UserID=" + txtUserId.Text.Trim(' ')
+ "; Password=" + txtPwd.Text.Trim(' ') + ";LibraryList=*USRLIBL;";
try
{
cn.Open();
}
catch (iDB2CommErrorException x)
I would like to be able to establish the connection 1 time when the application starts and then be able to use it
across all of the windows forms.
Just not sure were or how to define it.
Any help would be appreciated.
Thanks
|
|
|
|
|
It would be a bad idea to keep the database connection open constantly, It is much better to create a connection each time you need one.
I tend to use a class that does all my database work, which includes creating a connection when needed. This class provides functions for specifying search criteria. You could consider a simple class that simply takes an SQL query string and returns a datatable of the results (for search functionality) - In this case database connection string could be a static member of the class which is set when the application first loads.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Create a data class that handles all data calls to & from the data source. I have one if you need it.
Then in your main class, mine is called csApp, create a class variable that holds it:
public static DataClass DataAccess;
Next, in the Main method do:
public static void Main(String[] args)
{
DataAccess = new DataClass();
}
Then, anytime you need to call into the data source you can do:
DataSet ds = csApp.DataAccess.GetDataSet("select * from ....")
This way it's always available. And you should always close the connection when you're
not using it.
Everything makes sense in someone's mind
|
|
|
|
|
Hi
You can an app.config file to your project and write this code into it
<configuration>
<appsettings>
<add key="Accesskey" value="Data source=;Initial catalog=;user id=;Password=">
if you have done this write this code your destination form where you have to make connection.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
SqlConnection connection;
string con;
public Form1()
{
con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString();
connection = new SqlConnection(con);
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
connection.Open();
}
}
}
Here this code writern in C# language you have to just convert it into VB.NET.
|
|
|
|
|
hi
?xml version="1.0" encoding="utf-8" ?
<configuration>
<appSettings>
<add key="Accesskey" value="Data source=.;Initial catalog=kirti;user id=sa;Password=./>
</appSettings>
</configuration>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
SqlConnection connection;
string con;
public Form1()
{
con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString();
connection = new SqlConnection(con);
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
connection.Open();
SqlCommand commad = new SqlCommand("select *from " + textBox1.Text.ToString() + "", connection);
SqlDataAdapter ad = new SqlDataAdapter(commad);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
connection.Close();
}
}
}
}
This code is writren in C# you have just convert into VB.NET.
|
|
|
|
|
Hi all,
Can some one tell me how can I get a list of different DBMS/ Database server, those are installed in a computer using C#.
|
|
|
|
|
For SqlServer only:
private void GetServerList()
{
DataTable dt;
dt = SmoApplication.EnumAvailableSqlServers(false);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
ServerNamesComboBox.Items.Add(dr["Name"]);
}
ServerNamesComboBox.SelectedIndex
= ServerNamesComboBox.FindStringExact(
System.Environment.MachineName);
if (ServerNamesComboBox.SelectedIndex < 0)
{
ServerNamesComboBox.SelectedIndex = 0;
}
}
else
{
ExceptionMessageBox emb = new ExceptionMessageBox();
emb.Text = Properties.Resources.NoSqlServers;
emb.Show(this);
}
}
cannot help with non-SqlServer DBMSs.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for reply.
But I can not run this because of the following errors:
Error 2 The name 'SmoApplication' does not exist in the current context
Error 3 The type or namespace name 'ExceptionMessageBox' could not be found (are you missing a using directive or an assembly reference?)
Error 4 The type or namespace name 'ExceptionMessageBox' could not be found (are you missing a using directive or an assembly reference?)
Error 5 'WindowsApplication1.Properties.Resources' does not contain a definition for 'NoSqlServers'
|
|
|
|
|
All of the code can be run using standard .NET Framework references.
Google, or search MSDN, for smoapplication. From there you will find links to information that will help you to get it running.
As part of the process you will have to add references to the following assemblies:
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer;
using Microsoft.SqlServer.MessageBox;
The code comes from one of the SqlServer samples downloads, from MSDN.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks I m getting the result of your code. But it is not providing me the actual result that I needed.
|
|
|
|
|
I have a windows service multithreaded application for indexing purpose which have six threads. It is working fine except memory leakage. Actually when the service is started, then the service is consuming 12,584kb memory, after some time it is taking memory of 61,584 kb. But after indexing process is complete it is not releasing memory. I need it come back to its previous position after the indexing is complete, that is it should take the memory with which it started e.g. 12,584kb in this case. I have used garbage collection but it is not doing what I want.
Can anyone please help me?
|
|
|
|
|
Are you sure it's actually using that memory. Task Manager reports the amount of memory a process has reserved, not how much it's using. If that memory is needed elsewhere and your app isn't using it, it will be reclaimed.
In case it is, make sure that any objects you are using that have a Dispose method have that called once you are done with them [Edit] or better still, if possible use using blocks [/Edit]. If you are using any PInvoke, make sure you are releasing any unmanaged resources too.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Task Manager is telling you how much memory is reserved for the .NET CLR your app is running under. It's entirely possible for the CLR to reserve that much memory even though your app is not using it. The reason for this is because the CLR watches what your app has done and since it already allocated a large amount of memory, it'll keep the memory around in case your app wants it again. It's fast to allocate an object with memory that is already in the Managed Heap than it is to wait for the CLR to request memory from Windows, add it to the Managed Heap, then make the allocation.
|
|
|
|
|
Hello,
i am using a webbrowser control on my form together with textboxes. What i need is that when i load the form the cursor will be in textbox, but instead the webbrowser "steals focus". I have tried using the Focus() property for the textbox in just about anywhere now but it still wont work. Also i have tried creating event handlers for webbrowser's different events (GotFocus, Validated etc) but nothing seems to work.
The only thing that worked was the DocumentCompleted handler, which can make the cursor go to the textbox but not when the form loads, which is strange, since i have the browser go to a web page when the form loads (after InitializeComponent).
TY
|
|
|
|
|
What you need to do is set the Tab Order. This indicates which controls get the input focus in which order when you press tab to switch between them. The lowest tab order control gets the focus first on form load. Simple.
Tab order is initialy assigned in order of control creation, so if you create your browser first, then create the textboxes, the browser gets the focus.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|