|
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
|
|
|
|
|
I forgot to mention it, but tab order has been set properly. The cursor still goes to google.com's search bar (google.com is the site being automatically loaded into webbrowser at startup).
|
|
|
|
|
Just tried it, with a browser docked in a panel, and a textbox with button outside the panel. Set URL to "http:\\www.Google.co.uk" in design properties, TabIndex is Textbox = 0, button = 1, panel = 2.0
Works fine, Cursor in textbox on form load. How is this different from yours?
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
|
|
|
|
|
Its not different. When i do the same thing, the cursor automatically goes to webbrowser
I just discovered that the problem exists only with some pages (google, orkut, youtube, hotmail etc). When i use any of my local sites (.ee) then it works just fine.
Why is that so? google and microsoft using some fancy scripts?
modified on Wednesday, September 2, 2009 2:54 AM
|
|
|
|
|
How can I prevent the ^ character from being typed in a textbox? The problem seems to be that the character is not added before another keydown/keyup event.
For some other keys I used the following code to prevent them from being typed:
void textBox_KeyUp(object sender, KeyEventArgs e)
{
if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
{
if (e.PlatformKeyCode <= 12)
e.Handled = true;
switch (e.PlatformKeyCode)
{
case 226:
e.Handled = true;
break;
}
}
else if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
{
switch (e.PlatformKeyCode)
{
case 52:
e.Handled = true;
break;
case 186:
e.Handled = true;
break;
}
}
}
However, this does not work for the ^ character.
Thanks for help!
|
|
|
|
|
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '^')
{
e.Handled = true;
}
}
|
|
|
|
|
Couple of things:
1) KeyUp is probably not a good place to disable keys, as KeyPress happens repeatedly before KeyUp occurs. Try handling KeyDown, KeyPress and KeyUp with Console.WriteLine in each to show the flow of events.
2) If you are going to use magic numbers then comment the damn things so the next poor sod stands a chance of understanding what you are doing:
case 52: is a lot more useful than
case 52: By preference, use '%' instead of magic numbers, or constants with sensible names, or even "Keys."
3) Use KeyPress to disable your code:
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '^')
{
e.Handled = true;
}
}
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
|
|
|
|