|
SqlConnection conn = new SqlConnection((ConfigurationManager.ConnectionStrings["HASDBConnectionString1"]).ToString());
hi the above code is what i used in my asp.net to get the connection string from the web.config
now i am trying to get the connection string for my c# window application using visual studio 2005 project
but it sseems the same code dont work can any one show me how?
|
|
|
|
|
Check System.Configuration namespace.
alternatively
My suggestion is to create custom ConfigurationManager sigleton class , initialize at the startup.
BAIJUMAX
"Coolest thing on earth is...? Guess what? as per my knowledge 'ICE' , anythingelse pl's let me know "
|
|
|
|
|
In desktop application u should use
System.Configuration.ConfigurationSettings.AppSettings.Get("ElementName")
|
|
|
|
|
<configuration>
<add name="HASDBConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HASDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</configuration>
hi the above is the part of the configuration file that i am trying to get..
the connection string part.
i tried your method but it doesnt seems to work could you please try to help me again pls?
|
|
|
|
|
<configuration>
<appsettings>
<add key="Connection string" value="server=machinename;database=dbname;">
<add key="Server" value="machinename">
<add key="Database" value="dbname">
you have to modify your app.config file to look like above.
then u can use what i said earlier..
try it and if u still not been able to do it.
then i'll make a sample for u.
|
|
|
|
|
yes an sample would be nice thx u
as my situation is that i am trying to use the connection string in my app.config
however i only know how to do it in an window application
thx in advance
|
|
|
|
|
hello,
i have an MDI form that called FORM1
an I have a child form FORM2
I wrote:
form2.MDIPerent = form1
it works but in the side i get scroll bars
how I get over the scroll bars?
|
|
|
|
|
Hello,
Have you set "AutoScroll" property to "true"?
All the best,
Martin
|
|
|
|
|
if u put in auto scroll = true
the form couldn't be aMDI CONTAINER
|
|
|
|
|
Ahhhh!
|
|
|
|
|
I am about to make an application which have several features:
Application Name: Tictactoe
Features:
1. Game can be played on network and over the internet?
2. Make dll of that application and integrate with msn messanger or skype?
3. Add chat capability to game
4. Select Image or browse image to upload to play game and that image will be used instead of "X" or "o" in the game
5. Users can play with each other or can also play with PC. For PC levels of playing game can also be set "Easy", "Medium", "Hard".
6. Record the scores in the XML file to view highest scorers
The main query is that I never made a game before and never worked with XML file. Also i never worked in network programming in C# as i did in java long time before.
Can somebody suggest me what knowledge i need to know before start programming following.
As I know many application of tictactoe are there on internet but i want all coding myself with help of your people as i got very good response in this forum.
|
|
|
|
|
|
This isn't an answer to your question. Instead, I want to praise you for wanting to code this yourself. Well done you - and when you've finished, may I suggest that you take the lessons that you learned and write an article on it?
Seriously, with an attitude like this I think you will do very well (and that's why you've got my 5).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks I will..It will take me time but as soon i finish this application i will upload all files and doc for that application.
For the time being I need some directions to read some tutorials. Can you suggest me some good one's as until now i did some basic small applications now i am moving towards some complex applications.
|
|
|
|
|
shah123 wrote: Game can be played on network
shah123 wrote: Record the scores in the XML
shah123 wrote: I never made a game before and never worked with XML file. Also i never worked in network programming
So you want to write a quite complex application, using techniques that individually you have no idea how to use? Something here hints at course work where you have not been attending class!
Anyway, my advice to you is break it down into individual parts before you try to write the entire application. I suggest you get accustomed to working with Sockets for networking, as well as reading and writing Xml files and compiling simple applications into dll's and exe's
|
|
|
|
|
J4amieC thanks for ur suggestion..This is not course work but something i need to build on kind of request. This will also develop my programming techniques as i am not very expert but trying to learn many things through different applications.
|
|
|
|
|
Hey guys, i'm writing an app which must play audio and video files using directx 9 (9.0c). I've been googeling for a while to find a good book about DirectX but must of them seem to be focussed to game development. My aim is to learn the DirectSound, AudioVideoPlayback and a little of the DirectDraw library.
I've been reading a lot about books and everyone seems pretty negative about DirectX books written.
Does anyone have some recommendations about DirectX books? My current knowledge of DirectX is pretty poor, but i'm a pretty experienced developer having about 10 years of development experience of which 4 or 5 using the MS.NET
|
|
|
|
|
hi all,
How can i extract email-ids from windows address book?
any idea????????
thanking you in advance
jaz
|
|
|
|
|
Hi @all,
i'm realy distressed so i hope someone can help me...
What i want ist to call a native function declared in an API dll from a 3rd party application. Ok, it's not hard to do that.
The method construction looks like that :
<br />
BOOL WINAPI theFunc(SomeNotToDescribeObject *pObject, LPTSTR szPath)...<br />
This method gets an object, generate a file from that and put it in the TEMP folder of the current context. The OUT argument gives me the path where the file have been stored in. That's it.
My call:
<br />
[System.Runtime.InteropServices.DllImport("mydll.dll")]<br />
static extern unsafe bool theFunc([MarshalAs(UnmanagedType.Interface)] SomeNotToDescribeObject obj, StringBuilder buffer);<br />
<br />
StringBuilder buffer = new StringBuilder(260);<br />
try<br />
{<br />
bRet = teFunc(obj, buffer);<br />
}...<br />
That works... Ok, and where is my problem??? It works just in an windows forms application [with 2003 and 2005]. Not in an C# Windows Service under VS2005.
The strange thing with it is that it works on .NET 1.1 service with VS.NET 2003 but not in 2.0 VS2005. I don't understand that yet.
The service [2005] i write runs under local system. So, my thought was that the function try to write the filoe into the %userprofile%Temp folder and the service got no rights to write into that folder. So i bending my environment variables for the temp folder [uservariables for the current user] all to c:\windows\temp. The same effect.. It won't work. Then i try to run the service under the local user account, with c:\windows\temp and %userprofile%temp, combined with allow interaction with desktop and so on... Nothing works...
The strange thing is that it works in an Windows Forms application under .NET 2.0 on the same machine. I don't think that it is the call that fails. It have to be something with the assembly permissions or whatever...
So what is the main difference between an Windows Forms application and an NT service under .NET? I temped to change Service properties like them in the Windows Forms application. Or what is the diffrence between an NT Service written with VS2003 and VS2005? What can i do to call my needed method from my windows service?
Regards
|
|
|
|
|
Hi,
I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.
The code is here
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(strConnection);
//conn.Open();
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
// command.Connection = conn;
// command.CommandType = CommandType.Text;
// command.CommandText = "SELECT * FROM [Sheet1]";
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
conn.Open();
da.Fill(ds, "EmpSal");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//da.Fill(dt);
conn.Close();
lblError.Text="The Excel sheet has been read";
//return dt;
}
catch (Exception ex)
{
Response.Write( ex.Message);
//return null;
}
}
the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)
Regards
Vijay.
|
|
|
|
|
Hi All,
Can anybody let me know how to convert numeric values into words
ex.. 723890-- Seven Lakh Twenty Three Thousand Eight Hundred Ninety Only
But plz give me the answer of my this problem into indian currency meand hundreds,thousands,lakhs,crores.............................and etc
Thnx in advance
|
|
|
|
|
|
Hello,
I am having an EventReader.cs class which is polling for the events from the server. It is done thru Thread. The class EventReader.cs is as follows:
EventReader.cs
==================================Start of “EventReader.cs”==============
<br />
using System;<br />
<br />
using System.Collections.Generic;<br />
<br />
using System.Text;<br />
<br />
using DemoClient.PerspectiveMgtAPI;<br />
<br />
using System.Threading;<br />
<br />
using System.Diagnostics;<br />
<br />
using System.Collections;<br />
<br />
using System.ComponentModel;<br />
<br />
<br />
<br />
namespace DemoClient.proxy<br />
<br />
{<br />
<br />
public class EventReader : BackgroundWorker<br />
<br />
{<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
private readonly PerspectiveMgtProxy mPerspectiveMgt;<br />
<br />
private readonly Queue<EventInfo> mEventQueue;<br />
<br />
<br />
<br />
private bool mStatus;<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
public void runPoller ()<br />
<br />
{<br />
<br />
while (mStatus)<br />
<br />
{<br />
<br />
Console.WriteLine("Reading events in the Poller....****************************");<br />
<br />
<br />
<br />
EventInfo[] events = mPerspectiveMgt.getService().getEvents(mPerspectiveMgt.getSessionId());<br />
<br />
Console.WriteLine("Getting events: " + events.Length);<br />
<br />
foreach (EventInfo eventInfo in events)<br />
<br />
{<br />
<br />
fireEvent(eventInfo);<br />
<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
public EventReader (PerspectiveMgtProxy aPerspectiveMgt)<br />
<br />
{<br />
<br />
mPerspectiveMgt = aPerspectiveMgt;<br />
<br />
<br />
<br />
mEventQueue = new Queue<EventInfo>(); <br />
<br />
<br />
<br />
Thread pollerThread = new Thread(new ThreadStart(runPoller));<br />
<br />
pollerThread.IsBackground = true;<br />
<br />
pollerThread.Start(); <br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public void start ()<br />
<br />
{<br />
<br />
mStatus = true; <br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public void stop ()<br />
<br />
{<br />
<br />
mStatus = false; <br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
private void fireEvent (EventInfo anEventInfo)<br />
<br />
{<br />
<br />
Console.WriteLine("(*) fireEvent: " + anEventInfo.eventName);<br />
<br />
Console.WriteLine("(*) Event: " + EventName.DispletAdded.ToString()); <br />
<br />
<br />
<br />
if (anEventInfo.eventName == EventName.DispletAdded.ToString())<br />
<br />
{<br />
<br />
fireDispletAdded(anEventInfo);<br />
<br />
}<br />
<br />
<br />
<br />
String objectType = anEventInfo.sourceType;<br />
<br />
int objectId = anEventInfo.sourceId;<br />
<br />
<br />
<br />
EventName eventType = findEventType(anEventInfo.eventName);<br />
<br />
if (eventType == null)<br />
<br />
{<br />
<br />
Console.WriteLine("TODO: specified event not available");<br />
<br />
return;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private EventName findEventType (String anEventName)<br />
<br />
{<br />
<br />
try<br />
<br />
{<br />
<br />
return (EventName)Enum.Parse(typeof(EventName), anEventName);<br />
<br />
}<br />
<br />
catch (Exception e)<br />
<br />
{<br />
<br />
Console.WriteLine("No event is found with the given name: " + anEventName);<br />
<br />
}<br />
<br />
<br />
<br />
return 0;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void pushEventToQueue (EventInfo anEventInfo)<br />
<br />
{<br />
<br />
lock (this)<br />
<br />
{<br />
<br />
<br />
mEventQueue.Enqueue(anEventInfo);<br />
<br />
<br />
<br />
Monitor.Pulse(this);<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private EventInfo popEventFromQueue ()<br />
<br />
{<br />
<br />
lock (this)<br />
<br />
{<br />
<br />
while (mEventQueue.Count == 0)<br />
<br />
{<br />
<br />
Monitor.Wait(this);<br />
<br />
} <br />
<br />
<br />
<br />
return mEventQueue.Dequeue();<br />
<br />
} <br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void fireDispletAdded (EventInfo anEvent)<br />
<br />
{<br />
<br />
Console.WriteLine("fireDispletAdded (Event=" + anEvent + ")");<br />
<br />
<br />
<br />
String[] values = anEvent.values;<br />
<br />
<br />
<br />
<br />
int perspectiveId = anEvent.sourceId;<br />
<br />
int displetId = Convert.ToInt32(values[0]);<br />
<br />
<br />
<br />
ObjectId pId = new ObjectId();<br />
<br />
pId.id = perspectiveId;<br />
<br />
<br />
<br />
Perspective perspective = PerspectiveMgtProxy.getInstance().findPerspective(pId);<br />
<br />
<br />
<br />
ObjectId dId = new ObjectId();<br />
<br />
dId.id = displetId;<br />
<br />
<br />
<br />
Displet displet = PerspectiveMgtProxy.getInstance().getDisplets(new ObjectId[] {dId})[0];<br />
<br />
<br />
<br />
<br />
IEnumerator myEnumerator = EventListenerList.getInstance().getPerspectiveListeners().GetEnumerator();<br />
<br />
while(myEnumerator.MoveNext())<br />
<br />
{<br />
<br />
PerspectiveListener listener = ((PerspectiveListener)myEnumerator.Current);<br />
<br />
<br />
<br />
PerspectiveEvent perspectiveEvent = new PerspectiveEvent(perspective, displet);<br />
<br />
listener.displetAdded(perspectiveEvent);<br />
<br />
<br />
<br />
Console.WriteLine("fireDispletAdded invoked.");<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
}
===============================End of “EventReader.cs”==========================
I am getting the geometry for the sources as well the Name & Path of the source from the server. I am drawing the labels to show the sources at the runtime. I have created a Window Form “PerspectiveWindow.cs” which is containing those labels showing the sources. Now when a new source is being added at the server side I am using “DispletAdded” Event to update my PerspectiveWindow and draw the respective displet containing the source. I am doing this in a internal class in “PerspectiveWindow.cs” itself. I am able to get the events but I am not able to draw the new displet on the Window since an exception is raised at the time of adding the control to the Form as a Label with the respective geometry and name.
mWindow.Controls.Add(label1); -- This line raises the exception InvalidOperationException : “Cross-thread operation not valid: Control "PerspectiveWindow" accessed from a thread other than the thread it was created on.”
The code snippet for PerspectiveWindow.cs is as follows:
PerspectiveWindow.cs
======================Start of File “PerspectiveWindow.cs”=========================
<br />
using System;<br />
<br />
using System.Collections.Generic;<br />
<br />
using System.ComponentModel;<br />
<br />
using System.Data;<br />
<br />
using System.Drawing;<br />
<br />
using System.Text;<br />
<br />
using System.Windows.Forms;<br />
<br />
using DemoClient.proxy;<br />
<br />
using DemoClient.PerspectiveMgtAPI;<br />
<br />
<br />
<br />
namespace DemoClient<br />
<br />
{<br />
<br />
public partial class PerspectiveWindow : Form<br />
<br />
{<br />
<br />
<br />
<br />
private Perspective mPerspective;<br />
<br />
private PerspectiveListener mPerspectiveHandler;<br />
<br />
<br />
<br />
<br />
<br />
public PerspectiveWindow ()<br />
<br />
{<br />
<br />
InitializeComponent();<br />
<br />
}<br />
<br />
<br />
<br />
public void init (Perspective aPerspective)<br />
<br />
{<br />
<br />
mPerspective = aPerspective;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public void PerspectiveWindow_Load (object sender, EventArgs e)<br />
<br />
{<br />
<br />
Console.WriteLine("OnLoad....");<br />
<br />
<br />
<br />
if (mPerspective == null)<br />
<br />
return;<br />
<br />
<br />
<br />
Console.WriteLine("Perspective: " + mPerspective.ToString());<br />
<br />
<br />
<br />
SuspendLayout();<br />
<br />
<br />
<br />
this.Text = mPerspective.getName();<br />
<br />
this.Size = mPerspective.getDimension(); <br />
<br />
<br />
<br />
ResumeLayout(false);<br />
<br />
PerformLayout();<br />
<br />
<br />
<br />
Console.WriteLine("Perspective widget added to the Perpective window");<br />
<br />
<br />
<br />
mPerspectiveHandler = new PerspectiveEventHandler(this); <br />
<br />
mPerspective.addPerspectiveListener(mPerspectiveHandler);<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
internal class PerspectiveEventHandler : PerspectiveListener<br />
<br />
{<br />
<br />
private PerspectiveWindow mWindow;<br />
<br />
<br />
<br />
public PerspectiveEventHandler (PerspectiveWindow aWindow)<br />
<br />
{<br />
<br />
mWindow = aWindow;<br />
<br />
}<br />
<br />
<br />
<br />
public void displetAdded (PerspectiveEvent anEvent)<br />
<br />
{<br />
<br />
Console.WriteLine("(+) Displet added: ", anEvent);<br />
<br />
drawDisplet();<br />
<br />
Console.WriteLine("(+) Displet added returned.");<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public void displetRemoved (PerspectiveEvent anEvent)<br />
<br />
{<br />
<br />
Console.WriteLine("(-) Displet removed: ", anEvent);<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public void displetsZOrderChanged (PerspectiveEvent anEvent)<br />
<br />
{<br />
<br />
Console.WriteLine("(-) displetsZOrderChanged: ", anEvent);<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
private void drawDisplet ()<br />
<br />
{<br />
<br />
DispletInfo info = new DispletInfo();<br />
<br />
<br />
<br />
String sourceName = info.name;<br />
<br />
<br />
<br />
<br />
Label label1 = new Label();<br />
<br />
label1.BackColor = System.Drawing.SystemColors.ControlLightLight;<br />
<br />
label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;<br />
<br />
label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F,<br />
<br />
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));<br />
<br />
label1.Location = new System.Drawing.Point(info.x, info.y);<br />
<br />
label1.Size = new System.Drawing.Size(info.width, info.height);<br />
<br />
label1.TabIndex = 1;<br />
<br />
label1.Text = sourceName;
<br />
<br />
<br />
mWindow.Controls.Add(label1);
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
}
Please let me know if there are any other doubts.
Any help will be appreciated.
Thanks & Regards,
Kapil Singhal
|
|
|
|
|
|
This is probably also an interesting read for you: What's up with BeginInvoke?[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|