|
Look at the classes of System.Collection and System.Collection.Specialized namespaces. I normally use HashTable and store objects by name then retrieve them by name as well and cast to the type of the class that was stored. When I need to access objects by index then I use SortedList. And to store name value pair of strings you can use NameValuePairCollection.
|
|
|
|
|
Hi can you pls integrate this
program to retrive all databases of local host
----------------------------------
private void button3_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
String strServerName, strUserName, strPassword;
SqlConnection sqlServerConnectionObject = new SqlConnection();
SqlDataReader sqlDataReaderObject;
SqlCommand sqlCmdObject;
strServerName = "localhost";
strUserName = "sa";
strPassword = "san";
sqlServerConnectionObject.ConnectionString = "Persist Security Info=False;database=master;server=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword;
sqlServerConnectionObject.Open();
sqlCmdObject = new SqlCommand("Select * from sysdatabases",sqlServerConnectionObject);
sqlDataReaderObject = sqlCmdObject.ExecuteReader();
while (sqlDataReaderObject.Read() == true)
{
String strDatabaseName = sqlDataReaderObject.GetString(0);
listBox1.Items.Add(strDatabaseName);
}
}
--------------------------
program to retrive all tables of local host
----------------------------------------------
private void button4_Click(object sender, System.EventArgs e)
{
listBox2.Items.Clear();
string strDatabase=listBox1.SelectedItem.ToString();
MessageBox.Show(strDatabase);
String strServerName, strUserName, strPassword;
SqlConnection sqlServerConnectionObject = new SqlConnection();
SqlDataReader sqlDataReaderObject;
SqlCommand sqlCmdObject;
strServerName = "localhost";
strUserName = "sa";
strPassword = "san";
sqlServerConnectionObject.ConnectionString = "Persist Security Info=False;database=" + strDatabase + ";server=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword;
sqlServerConnectionObject.Open();
sqlCmdObject = new SqlCommand("Select * from sysobjects where type='u'",sqlServerConnectionObject);
sqlDataReaderObject = sqlCmdObject.ExecuteReader();
while (sqlDataReaderObject.Read() == true)
{
String strDatabaseName = sqlDataReaderObject.GetString(0);
listBox2.Items.Add(strDatabaseName);
}
sqlCmdObject.Dispose();
sqlServerConnectionObject.Close();
sqlServerConnectionObject.Dispose();
}
-----------------------------------------------------
Program to retrive all coulmsn of tables of local host
------------------------------------------------------------
private void button5_Click(object sender, System.EventArgs e)
{
//listBox1.Items="";
MessageBox.Show(listBox2.SelectedItem.ToString());
listBox3.Items.Clear();
SqlConnection conn = new SqlConnection("Integrated Security=yes;Initial Catalog=" + listBox1.SelectedItem.ToString() + ";Data Source=(local)");
conn.Open();
SqlCommand command = new SqlCommand("select * from " + listBox2.SelectedItem.ToString() , conn);
SqlDataAdapter adapter=new SqlDataAdapter(command);
DataSet dataset=new DataSet();
adapter.Fill(dataset, listBox2.SelectedItem.ToString() );
string s1=dataset.Tables[ listBox2.SelectedItem.ToString() ].Columns.ToString();
int j=1;
foreach(DataColumn column in dataset.Tables[ listBox2.SelectedItem.ToString() ].Columns)
{
listBox3.Items.Add(column.Caption);
j=j+1;
}
dataset.Clear();
command.Dispose();
conn.Close();
conn.Dispose();
/*
int i1=listBox1.Items.Count;
MessageBox.Show("item Count=" + i1);
for(int i=0;i<i1;i++)
{
MessageBox.Show(listBox1.Items[i].ToString());
}
*/
}
---------------------------------------------------------------
Basically my requirement is that when the windows forms open dev1 farm is selcted and its crossponding
all the databases and tables names and columns names are stored in farm-config.xml file
I tried its getting hanged in loop I want to implement in single loop
Can you make this program i have to submit today i think Jaaged Array i will have to use
I was trying to do in ArrayList
Suppose
in my computer there are two databases A and B
A databases has two tables A1 and A2
B databases has two tables B1 and B2
A1 table has Two columns A3 and A4
A2 table has Two columns A5 and A6
B1 table has Two columns B3 and B4
B2 table has Two columns B5 and B6
See how will structure come when all the tables names,databases names and columns names are stored
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="dev1">
<connection address="192.168.1.12" user="root" selectedConnection="1" password="daask">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="A" sourceType="amacs">
<tables state="0" name="A1">
<columns state="0" name="A3" />
<columns state="0" name="A4" />
</tables>
<tables state="0" name="A2">
<columns state="0" name="A5" />
<columns state="0" name="A6" />
</tables>
</database>
<database state="0" name="B" sourceType="amacs">
<tables state="0" name="B1">
<columns state="0" name="B3" />
<columns state="0" name="B4" />
</tables>
<tables state="0" name="B2">
<columns state="0" name="B5" />
<columns state="0" name="B6" />
</tables>
</database>
</farm>
<farm name="dev2">
<connection address="192.168.1.13" user="root" selectedConnection="1" password="">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-11" starttime="11:41:12" enddate="2005-05-11" endtime="12:11:31" />
<state>1</state>
</connection>
</farm>
</farm-config>
</root>
I have given the code for separete only thing you have integrate when farm=dev1 seleceted
all the databases name and tables names and columsn names are stored in tp xml file
I am getting too confused in loop
regards
sanjeev
|
|
|
|
|
hi,
Are u sure that Column name part is working?
"SqlCommand command = new SqlCommand("select * from " + listBox2.SelectedItem.ToString() , conn);
"
I think this SQL Stattement is wrong.
To find Columns use following Query:
"select Column_Name from INFORMATION_SCHEMA.columns where Table_name='"+listBox2.SelectedItem.ToString()+"'"
|
|
|
|
|
Hi
EVerything is correct in my code This code retives after particluar selection from listbox.
I have to dynamically retrive all databases and tables names and columns names of local host
in single connection. These all names will be storeed into xml file
i think i will have to use jagged array.
How can i store all the adatabaes names ,tables names and columdn names in jagged array so that i can store into xml file
can someone integrate all the sql statement in single SqlConnection statement
using Jagged array or something better from the view of Optimization
regards
sanjeev
|
|
|
|
|
Use the code in:
button3_Click
To create a method:
StringCollection GetDatabaseNames() This method should return all the database names.
Use the code in:
button4_Clic
To create a method:
StringCollection GetTableNames(string dbName) This method should return all tables for a specific database name.
Use the code in:
button5_Click
To create a method:
StringCollection GetColumnNames(string dbName, string tableName) This method should return all columns for a specific database/tablename combination.
I won't go into xml details but following is a pseudo-code of what your code should look like:
StringCollection databases, tables, columns;<br />
databases = GetDatabaseNames();<br />
foreach (string dbName in databases){<br />
tables = GetTableNames(dbName)<br />
foreach (string tableName in tables){<br />
columns = GetColumnNames(dbName, tableName)<br />
foreach (string columnName in columns){<br />
<your code to store in xml><br />
}<br />
}<br />
}
|
|
|
|
|
Reposting: I got no response in ASP.Net forum.
Hello everyone,
I have a question on using code-behind page-level static class members to preserve page-level data during click events and/or page refreshes. For example, if I have something like:
<code>
public class MyPage : System.Web.UI.Page
{
private static MyDataObject m_data;
private void Page_Load(object sender, System.EventArgs e)
{
if( !IsPostBack )
m_data = LoadMyData();
}
private void SaveButton_Click(object sender, System.EventArgs e)
{
}
}</code>
I'm hoping that when the user clicks to some other page on my website that this m_data object will be released from memory. And, I'm also hoping that if I have many people accessing this page at the same time, that each page will have its own m_data object created so that each user sees their properly loaded data.
Am I going about this wrong? Is there a better way? I've heard that page-level caching does not scale well in web farms, etc., so I'm trying to avoid that type of solution.
Thanks in advance,
~Brad
|
|
|
|
|
If you know when ASP.NET creates and destroys AppDomains for your webapp, you'll have the answer to this question also ( I don't). Static variables are static within their appdomain, so if ASP.NET maintains one AppDomain per webapp, then the static variables will be shared across pages.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
So basically, if 20 people are hitting that particular page, then they're all using the same static variable. Hrm. Not good.
|
|
|
|
|
Ask in the ASP.NET forum, you'll get more answers there.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Luis,
If you'll notice at the top of my original post, "Reposting: I got no response in ASP.Net forum."
Thank you.
|
|
|
|
|
I know this has to do with threading but I can't seem to get my head around the right way to do this. Originally I was doing this:
private void button1_Click(object sender, System.EventArgs e)
{
SpecialForm.SpecialForm infoBox;
infoBox = new SpecialForm.SpecialForm();
infoBox.setText("BlahBlah");
Thread.Sleep(5000);
infoBox.Close();
}
Which does not work...so I tried puttin it all in a seperate thread and it still does not work. Can anyone help?
-dustin
|
|
|
|
|
Also the SpecialForm is just a form that fades in and fades out when creating and closed. Also has to two methods, one for changing the text in a label and the other for updating a graphic in a pictureBox. It works fine when I get rid of the Thread.Sleep(5000) and the infoBox.Close() and put the infoBox.Close in another button. But of coarse that is manually closing it I need it to close itself after a certain amount of time.
|
|
|
|
|
You need to call BeginInvoke if you accessing the form from a different thread. See this[^] article to know more about BeginInvoke . The code to do what you want will look like
private void ThreadFunc()
{
Thread.Sleep(5000);
infoBox.BeginInvoke(new MethodInvoker(infoBox.Close(), null);
}
This will Close on the UI thread after 5 seconds. Hopefully that'll solve your problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Use a Timer object, and on the Tick event, close the form. Enable the timer in the constructor, and set its interval to 5000 ms.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi,
I would like to know how I can use document variables in C#.
I want to create a variable and store a string in it, then open the word document and retrieve the value of that variable.
Can anyone help me?
Thanks!
|
|
|
|
|
Hi ever body,
My question is how we can pass a string variable from c# project to a DLL using a matlab application. i shearched in Mx library and Mat libraries but i didn't found .
Thank u for ur help
|
|
|
|
|
I do it all the time. Just use the EngMATLib. Actually it's on this site!
1..2..3 ways of integrating MATLAB with the .NET[^]
I can pass a string like this to make a 3x3 matrix in matlab...
using (EngMATAccess mat = new EngMATAccess())
{
mat.Evaluate("A = [ 1 2 3; 3 5 6]"));
}
/\ |_ E X E GG
|
|
|
|
|
How we can do it in using DLL to call a matlab application?
|
|
|
|
|
Hi Guys , i want one help Regarding OPSEC SDK.
Open Platform for Security SDK is provided by Check point server which contains API's written in C also it contains many header files dlls etc..
I am new to C language and donot know how can i use the functions etc.. in C# with the matching datatypes....
Can anybody help me for writting the warpper class for it
Thanks and Regards,
Nitin.
|
|
|
|
|
|
Hi,
I've a problem with my image.
I use a function which take a .tif image with 128 colors input.
But I don't know how convert an image in 128 colors.
Do u have any ideas?
Thx for replies
Have a nice day
bibax en fait un max!
|
|
|
|
|
Hi,
I found how convert my image in 128 colors (2^7)
This is my code :
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
//chnage the filename to obtain a tif file
Console.WriteLine(rasterFileName);
int index = rasterFileName.IndexOf(".");
string rasterFileNameTif = rasterFileName.Substring(0,index);
rasterFileNameTif = rasterFileNameTif.Insert(index, ".tif");
Console.WriteLine(rasterFileNameTif);
try
{
// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID
// for the ColorDepth parameter category.
myEncoder = Encoder.ColorDepth;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
myEncoderParameters = new EncoderParameters(1);
// Save the image with a color depth of 7 bits per pixel (128 colors).
myEncoderParameter = new EncoderParameter(myEncoder, 24L);
myEncoderParameters.Param[0] = myEncoderParameter;
Console.WriteLine(myEncoder);
picChart.Image.Save(rasterFileNameTif,myImageCodecInfo,myEncoderParameters);
It works with all formats input
But when I have a tif file input (I want also tif output but in 128 colors), I have an exception :
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at displayRaster.displayRaster.ChangeRasterFormat() in c:\documents and settings\franck\mes documents\visual studio projects\displayraster\displayraster.cs:line 178
Do u know why?
Thx for replies.
Have a nice day
bibax en fait un max!
|
|
|
|
|
Hi,
I have a windows service in C# (.NET framework 1.1) running on Windows XP
PRO SP2. This service essentiallt starts a printjob watcher. Please see the code
snippet below.
queryInterval = ((SchedulerData)obj).Interval/1000;
//queryInterval=1;
this.printEventWatcher = new System.Management.ManagementEventWatcher();
this.printEventWatcher.Query = new System.Management.EventQuery("SELECT *
FROM __InstanceCreationEvent WITHIN "+queryInterval+" WHERE TargetInstance
ISA \"Win32_PrintJob\"");
string hostName = Dns.GetHostName();
this.printEventWatcher.Scope = new
System.Management.ManagementScope("\\\\"+hostName+"\\root\\CIMV2");
printEventWatcher.EventArrived+=new EventArrivedEventHandler(this.Arrived);
printEventWatcher.Start();
This service fires the EventArrived event when running as my login account.
i.e When the service is run as MaxBici and I login as MaxBici and print
documents, I see the events being fired.
But, when the service is run as NT AUTHORITY\SYSTEM (Local System account),
and I login as MaxBici and print documents the EventArrived event is not
fired.
The query interval was set to 1 second in both the above cases.
Could anyone help me with this?
What does the scope in the event watcher signify?
Isn't the data in the WMI tables visible to all users in a PC?
Thanks in advance.
Max
|
|
|
|
|
could u tell me about Integrated Security=SSPI, what is the role in database connection
|
|
|
|
|