Click here to Skip to main content
15,896,512 members
Home / Discussions / Database
   

Database

 
QuestionNeed to display the links in datalist of pros in redcolor who r working for us Pin
subbu.sk28-May-08 2:50
subbu.sk28-May-08 2:50 
QuestionBinary data with scripts... Pin
Chinners28-May-08 2:41
Chinners28-May-08 2:41 
AnswerRe: Binary data with scripts... Pin
Chinners29-May-08 5:24
Chinners29-May-08 5:24 
Questionneed to locate all the SQL servers and their databases in domain Pin
S.Aijaz28-May-08 1:54
S.Aijaz28-May-08 1:54 
Questionparameter problem Pin
Mr.Kode28-May-08 1:07
Mr.Kode28-May-08 1:07 
AnswerRe: parameter problem Pin
Mark J. Miller29-May-08 4:15
Mark J. Miller29-May-08 4:15 
QuestionApplication Side, SQL Queries. Pin
ctrlnick27-May-08 21:28
ctrlnick27-May-08 21:28 
AnswerRe: Application Side, SQL Queries. Pin
Mark J. Miller29-May-08 4:03
Mark J. Miller29-May-08 4:03 
Where you store the query text is probably immaterial, because wither you store the query in .resx or hard-code the query into the application you'll still need to recompile when you change the query. However, you should define an interface or at least a data layer class which defines the queries and their parameters and hides the implementation of how you call and execute your queries from your application.

If you are working with DataSet objects then your interface will define the return values as DataSet/DataTable objects. Otherwise, your interface will define the return values as your custom objects.

If you are working with a large number of queries you will need to define multiple interfaces which break up your queries into logical groups which match your object model.

Here's a simple implementation w/o using an interface:

implementation:
<br />
public class DataLayer {<br />
  public DataSet GetSomeData(int param1, string param2){<br />
    DataSet myData = new DataSet();<br />
<br />
    using(DbConnection conn = GetConnectionFactoryMethod()){<br />
      using(DbCommand cmd = new DbCommand(conn, "SELECT .... FROM .... WHERE col1 = @param1 AND col2 = @param2")){<br />
         cmd.Parameters.Add("@param1", .....);<br />
         cmd.Parameters.Add("@param2", .....);<br />
<br />
         cmd.Parameters["@param1"].Value = param1;<br />
         cmd.Parameters["@param2"].Value = param2;<br />
<br />
         DbDataAdapter da = new DbDataAdapter(cmd);<br />
         da.Fill(myData);<br />
      }<br />
    }<br />
<br />
    return myData;<br />
  }<br />
<br />
  public DataSet GetSomeDifferentData(string param1, bool param2){<br />
    // ...... implementation .....<br />
  }<br />
<br />
  private DbConnection GetConnectionFactoryMethod(){<br />
    return new SqlConnection("... connection string ...");<br />
  }<br />
}<br />


usage:
<br />
  DataLayer myDataLayer = new DataLayer();<br />
<br />
  DataSet myData = myDataLayer.GetSomeData(5, "my string");<br />
  DataSet myData2 = myDataLayer.GetSomeDifferentData("some value", true);<br />
<br />


By doing this you can store your query text however you like (I say just hard-code the query text into the data layer class). The advantage of doing it this way is that your queries are de-coupled from your application. You can change your data provider or switch to stored procedures or whatever. As long as you return the same dataset (or object) it doesn't matter how you do it.


Questionsql server locking mechanism Pin
MozhdehQeraati27-May-08 21:01
MozhdehQeraati27-May-08 21:01 
AnswerRe: sql server locking mechanism Pin
Ashfield27-May-08 21:10
Ashfield27-May-08 21:10 
GeneralRe: sql server locking mechanism Pin
MozhdehQeraati27-May-08 21:21
MozhdehQeraati27-May-08 21:21 
GeneralRe: sql server locking mechanism Pin
Ashfield27-May-08 21:36
Ashfield27-May-08 21:36 
QuestionUpdate an image field Pin
imannasr27-May-08 18:55
imannasr27-May-08 18:55 
AnswerRe: Update an image field Pin
Christian Graus28-May-08 14:28
protectorChristian Graus28-May-08 14:28 
NewsSQL Server 2008 Jumpstart Event Dev Training Now Online Pin
brucedkyle27-May-08 16:16
brucedkyle27-May-08 16:16 
QuestionIncorrect syntax on output parameter? [modified] Pin
markymark8227-May-08 10:34
markymark8227-May-08 10:34 
AnswerRe: Incorrect syntax on output parameter? Pin
Christian Graus27-May-08 14:25
protectorChristian Graus27-May-08 14:25 
GeneralRe: Incorrect syntax on output parameter? Pin
markymark8228-May-08 0:02
markymark8228-May-08 0:02 
QuestionVery slow ORDER BY Pin
legionnaire27-May-08 7:23
legionnaire27-May-08 7:23 
AnswerRe: Very slow ORDER BY Pin
Christian Graus27-May-08 14:26
protectorChristian Graus27-May-08 14:26 
QuestionVisual Studio Server Explorer issue... [modified] Pin
Rombolt27-May-08 6:21
Rombolt27-May-08 6:21 
QuestionUploading a website with a database Pin
Mohammad A Gdeisat27-May-08 5:36
Mohammad A Gdeisat27-May-08 5:36 
AnswerRe: Uploading a website with a database Pin
Krazy Programmer27-May-08 7:32
Krazy Programmer27-May-08 7:32 
Questionsql server connection?????or login with query analyzer???????????? Pin
mr.mohsen27-May-08 3:39
mr.mohsen27-May-08 3:39 
AnswerRe: sql server connection?????or login with query analyzer???????????? Pin
Mark J. Miller29-May-08 4:09
Mark J. Miller29-May-08 4:09 

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.