Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
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 
Generalapplication automatically does a repair Pin
econnor13-Jan-05 9:50
econnor13-Jan-05 9:50 
GeneralRe: application automatically does a repair Pin
Steve Maier13-Jan-05 10:31
professionalSteve Maier13-Jan-05 10:31 
GeneralRe: application automatically does a repair Pin
econnor13-Jan-05 10:41
econnor13-Jan-05 10:41 
GeneralUserControl _Click Event Pin
Radgar13-Jan-05 9:44
Radgar13-Jan-05 9:44 
GeneralRe: UserControl _Click Event Pin
Stefan Troschuetz13-Jan-05 23:30
Stefan Troschuetz13-Jan-05 23:30 
GeneralRe: UserControl _Click Event Pin
Radgar14-Jan-05 7:59
Radgar14-Jan-05 7:59 
GeneralSystem.messaging Pin
Esmo200013-Jan-05 9:17
Esmo200013-Jan-05 9:17 
GeneralRe: System.messaging Pin
Christian Graus13-Jan-05 9:39
protectorChristian Graus13-Jan-05 9:39 
GeneralRe: System.messaging Pin
Esmo200014-Jan-05 4:52
Esmo200014-Jan-05 4:52 

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.