|
thg971 wrote: The static class 'Hello' in my main project has to be accessed by the loaded classes. But only to the 'Hello' instance of the main projet (what I can't apparently do when using class from external assemblies)
Why doesn't it work? AFAIK, singletons remain single within an AppDomain, so as long as the external assemblies are also loaded in the same AppDomain as your Hello class, they should be accessing the same instance.
If not, then you would have to derive your singleton from MarshalByRef and modify the code in the external assemblies to explicitly accept an instance of your singleton (as a property setter, for example) and then use that instance.
|
|
|
|
|
how can i get index of specified item in multidimension array ?
|
|
|
|
|
By using nested for loops to step through and checking for when the element is equal to your value.
valueSearch = "Value to search for";
for (int x = 0; x < array.GetLength(0); x++)
{
for (int y = 0; y < array.GetLength(1); y++)
{
for (int z = 0; z < array.GetLength(2); z++)
{
if (array[x][y][z] == valueSearch)
{
}
}
}
}
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
I would say that if you need to be searching, arrays aren't the way to go.
But if you must use arrays, the only tip I would add to the above is a break statement jump out of the nested for loops when you actually find the value (no need in running through the rest of the items).
J
Make the logo bigger
|
|
|
|
|
True that
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Hi im new to Both C# and sql and exept from that my problem is:
I´ve managed to connect to a mssql database (express edition) from my C# program and I have the sqldata reader to read my question to listboxes in my windowsForm. Ive understood from "Beginners guide to accessing SQL Server through C#" that once you got your connection running and the reader has read the table in the database You can rephrase your question without reading directly to the database.
If that is correct, Is it possible to establish a connection to the sql database in "program.cs" and get your reader to read the whole table and then let different windowsForms make sql questions to that reader? Im hoping to gain less questions to the DB and its supposed to get the table every five minutes or something.
I would be very happy if anyone could help me in this matter
Here is an example of code in my Form:
public partial class BinMonitor : Form<br />
{<br />
private SqlConnection conn;<br />
private SqlCommand cmd;<br />
private SqlDataReader reader;<br />
string Sql;<br />
<br />
public BinMonitor()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
private void timer1_Tick(object sender, EventArgs e)<br />
{<br />
textBox1.Text = DateTime.Now.ToLongTimeString();<br />
<br />
}<br />
private void timer2_Tick(object sender, EventArgs e)<br />
{<br />
<br />
listBox1.Items.Clear();<br />
listBox2.Items.Clear();<br />
listBox3.Items.Clear();<br />
string connStr = "server=DBserver; user id=user; password=pwd; database=flights;Trusted_Connection=yes;";<br />
SqlConnection conn = new SqlConnection(connStr);<br />
conn.Open();<br />
reader = null;<br />
cmd = new SqlCommand("SELECT * FROM BinMonitor Where Departure !<" + "'" + textBox1.Text + "'" + "order by Departure ASC", conn);<br />
reader = cmd.ExecuteReader();<br />
reader.Read();<br />
<br />
while (reader.Read())<br />
{<br />
listBox1.Items.Add(reader.GetString(0));<br />
listBox2.Items.Add(reader.GetString(1));<br />
listBox3.Items.Add(reader.GetString(2));<br />
}<br />
}<br />
<br />
<br />
<br />
}<br />
}
Lost in space
|
|
|
|
|
I am very happy to help you, I would not know that you want to express the link MYSQL or other intention.
I hope you can more simple expression of what you mean.
MSN : chenqi1000y@163.com
|
|
|
|
|
Thank you for helping!
I was hoping to get an answer if its possible to make the sqlreader work for several Forms at the same time, and if so how?
|
|
|
|
|
erikhjerpe wrote: If that is correct, Is it possible to establish a connection to the sql database in "program.cs" and get your reader to read the whole table and then let different windowsForms make sql questions to that reader?
No. A reader is a one-time-forward-only view of the data that is being retrieved from the database. Once a row has been read from the reader you cannot go back and read it again.
You may wish to look into DataAdapters in order to Fill a DataSet with the data which you can store in a central location and allow the forms to access.
erikhjerpe wrote: Here is an example of code in my Form
It is unwise to access data dirctly from a form.
erikhjerpe wrote: cmd = new SqlCommand("SELECT * FROM BinMonitor Where Departure !<" + "'" + textBox1.Text + "'" + "order by Departure ASC", conn);
reader
This code is susceptable to SQL Injection Attacks. Please read up on SQL Injection Attacks and Tips on How to Prevent Them[^]
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Thank you very much for the tips, I certainly will look into DataAdapters, have a vague ideea that thats what I´m looking for. About Injection attacks Im´not afraid since the application is supposed for a closed network and without any input from users other than to load a form. (Trying to build a system of info displays).
Anyway thanks a lot for your answers
|
|
|
|
|
erikhjerpe wrote: About Injection attacks Im´not afraid since the application is supposed for a closed network and without any input from users other than to load a form
Statistically most system breaches are inside jobs.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
You´re right, at the moment I´m taking my first trembling steps in programming, and it´s probably a good Idea to learn from the start to think about security.
Thanks
|
|
|
|
|
We all have to start somewhere. Just a few tips of my own and I apologize if any are repeats.
Think stored procedures. That will solve the Sql injection attack problem by itself. At the very least use parameterized queries. This will solve more than just security issues. Imagine the headache of having to debug your app at 2am because somebody entered "Bob O'Malley" into a textbox?
put data connections, data readers, and commands into using statements. Especially the connections. Again, you don't want to be figuring out why your server came to a screeching halt at 2am because no connections ever closed.
DataSets are great, you can also use the reader to load that data into a collection of objects, close your connections, then pass the collection around anywhere you need it.
I know some of this may seem advanced if you're just getting started, but remember this is where you want to be going. It's never to early to start doing it right.
Oh, one more thing that I just noticed: you don't need a priming read on your datareader. This will actually cause you to throw away the first row of data. HTH.
J
Make the logo bigger
|
|
|
|
|
Dear all,
I am facing a problem with a javascript function i had with me javascript for country generation and also on change of country state generation w.r.t of country but i want to fetch the selected value of country and state and to update in the database using sqlserver.
sai krishna
|
|
|
|
|
If you divide your text into sentences, it might be possible to understand what you are trying to say.
As I gather it, you want to do something (update? insert?) with an MS SQL Server database from Javascript?
You can't do that. Well, it's possible, but that would mean that you expose your database login to everyone.
You have to post the information to the server, where you do the database work.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks guffa,
for ur prompt msg, but i have a javascript code written for country selection and this is the aspx statement i am writing to call javascript
but in the javascript onchange event is to give the corresponding state of the country another javascript so what i have to do to get the selected value of the country
thanks once again
sai krishna
|
|
|
|
|
I'm not entirely sure I understand your problem either, but what it sounds like you want to do is populate a state combo box based on the users selection in a country combo box. You don't want connection strings in your web page unless your resume is up to date. I think you're going to have to look into an ajax solution unless you want to do a full postback each time the user changes their selection.
J
Make the logo bigger
|
|
|
|
|
dsaikrishna wrote: I am facing a problem with a javascript function i had with me javascript for country generation and also on change of country state generation w.r.t of country but i want to fetch the selected value of country and state and to update in the database using sqlserver.
Okay.
#1. Declare one variable in code-behind to hold the status.
string selectedCountry = string.Empty;
#2. Add one server-side hidden field (a HTML hidden field with RunAt="Server") in your page.
<input id="Hidden1" type="hidden" runat="server" onserverchange="Hidden1_ServerChange"/><br />
#3. Add change event of this hidden field
<br />
protected void Hidden1_ServerChange(object sender, EventArgs e)<br />
{<br />
<br />
}
#4. In onchange event of Country list, you can set the value to this hidden field.. For example, if you select "Singapore" from combobox, set this to hidden field by using javascript.
var objHdf = document.getElementById('Hidden1');<br />
objHdf.value = document.getElementById('cboCountry').selectedtext;<br />
#5. As soon as the value of hidden field get changed, the server side event of hidden field will be invoked. So, get the value from hidden and set it to string that we declare earlier..
<br />
protected void Hidden1_ServerChange(object sender, EventArgs e)<br />
{<br />
selectedCountry = Hidden1.Value; <br />
}
Okay. now, you get the value so, you can insert it to SQL database..
Hope it helps..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
i would like to know how to create and use crystal reports in c#.net . do any one can briefly explain this.
|
|
|
|
|
1- you have to add crystal Report Viewer
2- add new crystal report on your applicatin (go to application solution explorer right click ,choice new item and choice crystal report)
3- you have to specify provider ado for example and choice the table
4- go to properties and choice your report in field report source
|
|
|
|
|
Hi guys I know this is simple but still could u help me out !
for instance I ve got 2 forms (in one project), in the first form i have a text box with a button, I enter something in the box and click the button. the second form pops up and i want to use that text that I entered previously, how can I do it ? cause if I creat a new instance of the first form all the values would be wiped out !
Thanx
Mr.K
|
|
|
|
|
You must get that data from your first form and give them to the second form you can do this using constructor for second form
if you see it from outside it would be like this (there are tons of other ways to do this)
<br />
<br />
Form1 frmGetData=new Form1();<br />
<br />
frmGetData.ShowDialog();<br />
<br />
Data myData=frmGetData.GetData();
<br />
Form2 frmUseData=new From2(myData);<br />
<br />
frmUseData.Show();<br />
<br />
good luck
|
|
|
|
|
|
Like I said here "Get control from another form"[^], you can create public property.
eg: Form1.
<br />
public string MyValue<br />
{<br />
get<br />
{<br />
return "This is my value";<br />
}<br />
}<br />
<br /> Form2
<br />
Form2 obj = new Form2();<br />
MessageBox.Show(obj.MyValue);
Hope it helps..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Hello Friends,
I had an mdiParent form and an other form2 (this is not child form).
their is an label on mdiParentForm whose text value is "XYZ" and I want to change its text value on the click event of button on form2 and at the same time it should reflect on mdiParentForm.
But i am unable to do so.
I am using this .
ON button_click event
i made an object of mdiParentForm
and with that object i change the text value of label but it is not reflected on mdiParent.
Regards,
rahul saini
|
|
|
|