Click here to Skip to main content
15,914,163 members
Home / Discussions / C#
   

C#

 
Questionhow can i restart or shutdown my computer by c# Pin
m.rastgar13-Jan-05 13:00
m.rastgar13-Jan-05 13:00 
AnswerRe: how can i restart or shutdown my computer by c# Pin
Dennis C. Dietrich13-Jan-05 14:55
Dennis C. Dietrich13-Jan-05 14:55 
AnswerRe: how can i restart or shutdown my computer by c# Pin
MoustafaS15-Jan-05 2:52
MoustafaS15-Jan-05 2:52 
GeneralFrom Java to C# Pin
Salman Taseer`13-Jan-05 11:15
Salman Taseer`13-Jan-05 11:15 
GeneralRe: From Java to C# Pin
Andy Brummer13-Jan-05 11:23
sitebuilderAndy Brummer13-Jan-05 11:23 
GeneralRe: From Java to C# Pin
Salman Taseer`13-Jan-05 11:30
Salman Taseer`13-Jan-05 11:30 
GeneralRe: From Java to C# Pin
Christian Graus13-Jan-05 11:53
protectorChristian Graus13-Jan-05 11:53 
GeneralBest practices for database password Pin
econner13-Jan-05 10:53
econner13-Jan-05 10:53 
GeneralRe: Best practices for database password Pin
ctescu13-Jan-05 11:01
ctescu13-Jan-05 11:01 
GeneralRe: Best practices for database password Pin
Colin Angus Mackay13-Jan-05 11:32
Colin Angus Mackay13-Jan-05 11:32 
GeneralRe: Best practices for database password Pin
Colin Angus Mackay13-Jan-05 11:33
Colin Angus Mackay13-Jan-05 11:33 
GeneralRe: Best practices for database password Pin
econner13-Jan-05 13:19
econner13-Jan-05 13:19 
GeneralC# Loop Through DataGrid Pin
Anonymous13-Jan-05 10:47
Anonymous13-Jan-05 10:47 
GeneralRe: C# Loop Through DataGrid Pin
Christian Graus13-Jan-05 11:54
protectorChristian Graus13-Jan-05 11:54 
GeneralRe: C# Loop Through DataGrid Pin
Anonymous17-Jan-05 12:04
Anonymous17-Jan-05 12:04 
GeneralRe: C# Loop Through DataGrid Pin
epinaud25-Jan-05 6:28
epinaud25-Jan-05 6:28 
GeneralSQL Connection Pin
.gonad13-Jan-05 10:44
.gonad13-Jan-05 10:44 
Can anyone tell me the best way to do this?

Form1 has a listview that pulls data from a sql table and displays it in the listview.

From Form1, how can i call a class that would make the SQL connection and run a query that would display my data to Form1?

basically, i have a lot of Forms that individually make a SQL connection, but in the event of having to change SQL servers, i dont want to have to go into all 20 of these forms to change the SQL Connection string to point to a new server.

Form1
-----
<br />
private void listfromDB()<br />
{<br />
  string sqlString = "select * from table";<br />
  mySQLClass getSQLdata = new mySQLClass();<br />
  getSQLdata.SQLdata(sqlString);<br />
  <...code to add data from query to listview...><br />
}<br />


Class1
------
<br />
public giveSQLdata(string _sqlString)<br />
{<br />
  string sqlCon = "workstation id=LOCALHOST;packet size=4096;...etc";<br />
  SqlConnection sqlConnect = new SqlConnection(sqlCon);<br />
  SqlCommand cmd = new SqlCommand(_sqlString, sqlConnect);<br />
  sqlConnect.Open();<br />
  SqlDataReader dr = cmd.ExecuteReader();<br />
  return something...<br />
}<br />


i'm new to this and need help...i freely admit this. Smile | :)
thank you so much for your help.
.gonad
GeneralRe: SQL Connection Pin
Colin Angus Mackay13-Jan-05 11:41
Colin Angus Mackay13-Jan-05 11:41 
GeneralRe: SQL Connection Pin
Paul Lyons13-Jan-05 15:16
Paul Lyons13-Jan-05 15:16 
GeneralRe: SQL Connection Pin
Colin Angus Mackay13-Jan-05 22:13
Colin Angus Mackay13-Jan-05 22:13 
GeneralRe: SQL Connection Pin
.gonad14-Jan-05 2:01
.gonad14-Jan-05 2:01 
GeneralFile sharing error / multiple processes in one click event... Pin
new_phoenix13-Jan-05 9:50
new_phoenix13-Jan-05 9:50 
GeneralRe: File sharing error / multiple processes in one click event... Pin
Dave Kreskowiak14-Jan-05 4:29
mveDave Kreskowiak14-Jan-05 4:29 
GeneralRe: File sharing error / multiple processes in one click event... Pin
new_phoenix14-Jan-05 11:44
new_phoenix14-Jan-05 11:44 
GeneralRe: File sharing error / multiple processes in one click event... Pin
Dave Kreskowiak14-Jan-05 12:16
mveDave Kreskowiak14-Jan-05 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.