Click here to Skip to main content
15,894,460 members
Home / Discussions / Database
   

Database

 
AnswerRe: Want a sql query or any solutation Pin
Krish - KP13-Feb-07 23:55
Krish - KP13-Feb-07 23:55 
QuestionSQL server in to XML Pin
indian14313-Feb-07 19:37
indian14313-Feb-07 19:37 
AnswerRe: SQL server in to XML Pin
N a v a n e e t h13-Feb-07 21:42
N a v a n e e t h13-Feb-07 21:42 
GeneralRe: SQL server in to XML Pin
indian14322-Feb-07 21:01
indian14322-Feb-07 21:01 
Questionrelatioships & datasets? [sqlservr 2005 , C# 05] Pin
giddy_guitarist13-Feb-07 19:32
giddy_guitarist13-Feb-07 19:32 
AnswerRe: relatioships & datasets? [sqlservr 2005 , C# 05] Pin
Colin Angus Mackay13-Feb-07 19:38
Colin Angus Mackay13-Feb-07 19:38 
GeneralRe: relatioships & datasets? [sqlservr 2005 , C# 05] Pin
giddy_guitarist13-Feb-07 20:03
giddy_guitarist13-Feb-07 20:03 
GeneralRe: relatioships & datasets? [sqlservr 2005 , C# 05] Pin
Colin Angus Mackay13-Feb-07 21:55
Colin Angus Mackay13-Feb-07 21:55 
giddy_guitarist wrote:
Or is there something on MSDN that would show me how to just get data from an sqlserver DB via C# code!. There are just some dumb wizard/ databinding examples.


Look at what the wizards create (not the best example in the world, auto-generated code rarely is, but it will show you against your database). You will find a filename.designer.cs file which contains all the autogenerated code.

The basic sequence for accessing the database in your code is aquire-query-release. Like this:
// Set up
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = queryOrStoredProcedureName;
cmd.CommandType = CommandType.StoredProcedure; // Only if the cmd is a stored procedure
cmd.Parameters.Add(parameter details); // If you need to add parameters. Repeat as required
 
// Aquire connection
conn.Open();
 
// Query - choose one only.
SqlDataReader reader = cmd.ExecuteReader(); // if you expect a result
cmd.ExecuteNonQuery(); // if you don't expect a result
object result = cmd.ExecuteScalar(); // if you only want the value of the first column of the first row only.
 
// If you have a data reader, then iterate over the reader if necessary
while(reader.Read())
{
    // Get the data from the reader as required.
}
 
// Release the connection
conn.Close();


Note: it is good practice to close the connection as soon as possible. The connections come from a pool so getting a new connection is quite fast.

You can also search MSDN on any of the class names given above. That will tell you more about what this does.


Generalsome newbie questions:[sqlservr 2005 , C# 05] Pin
giddy_guitarist16-Feb-07 4:32
giddy_guitarist16-Feb-07 4:32 
GeneralRe: some newbie questions:[sqlservr 2005 , C# 05] Pin
Colin Angus Mackay16-Feb-07 6:47
Colin Angus Mackay16-Feb-07 6:47 
GeneralRe: some newbie questions:[sqlservr 2005 , C# 05] Pin
giddy_guitarist18-Feb-07 0:31
giddy_guitarist18-Feb-07 0:31 
GeneralRe: some newbie questions:[sqlservr 2005 , C# 05] Pin
Colin Angus Mackay18-Feb-07 1:12
Colin Angus Mackay18-Feb-07 1:12 
GeneralRe: some newbie questions:[sqlservr 2005 , C# 05] Pin
giddy_guitarist18-Feb-07 2:37
giddy_guitarist18-Feb-07 2:37 
Questionsql triggers Pin
kalyan_241613-Feb-07 17:21
kalyan_241613-Feb-07 17:21 
QuestionJob Name Pin
Member 382635313-Feb-07 11:59
Member 382635313-Feb-07 11:59 
AnswerRe: Job Name Pin
Ennis Ray Lynch, Jr.13-Feb-07 12:13
Ennis Ray Lynch, Jr.13-Feb-07 12:13 
AnswerRe: Job Name Pin
Harini N K21-Feb-07 22:35
Harini N K21-Feb-07 22:35 
QuestionOrder of operations and Short circuit Pin
Keith Andersch13-Feb-07 9:51
Keith Andersch13-Feb-07 9:51 
AnswerRe: Order of operations and Short circuit Pin
Pete O'Hanlon13-Feb-07 10:13
mvePete O'Hanlon13-Feb-07 10:13 
GeneralRe: Order of operations and Short circuit Pin
Keith Andersch13-Feb-07 10:33
Keith Andersch13-Feb-07 10:33 
GeneralRe: Order of operations and Short circuit Pin
M A A Mehedi Hasan13-Feb-07 23:25
M A A Mehedi Hasan13-Feb-07 23:25 
GeneralRe: Order of operations and Short circuit Pin
Pete O'Hanlon13-Feb-07 23:45
mvePete O'Hanlon13-Feb-07 23:45 
QuestionProgram can't connect with the server ,, vb.net 2005 Pin
kindman_nb13-Feb-07 8:49
kindman_nb13-Feb-07 8:49 
AnswerRe: Program can't connect with the server ,, vb.net 2005 Pin
Pete O'Hanlon13-Feb-07 9:24
mvePete O'Hanlon13-Feb-07 9:24 
GeneralRe: Program can't connect with the server ,, vb.net 2005 Pin
kindman_nb13-Feb-07 9:30
kindman_nb13-Feb-07 9:30 

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.