473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Writing SQL Code in C#

21
Hi,
Will someone please help me with this.
I am using Visual Studio 2005 (C#).
I would like to write SQL queries in my code and assign it a variable thereafter.
Would someone please help me with this urgently.
Thanx.
Apr 12 '07 #1
4 1437
gomzi
304 100+
Hi,
Will someone please help me with this.
I am using Visual Studio 2005 (C#).
I would like to write SQL queries in my code and assign it a variable thereafter.
Would someone please help me with this urgently.
Thanx.
Your query cant be more vague than that man!!

anyway....
dim str as string = "select * from blah";

is this legal??yup.
Apr 12 '07 #2
Plater
7,872 Expert 4TB
I find the best method is to use a string and break it into parts.

string StringVarriableForLastName="Plater";
string myq="";

myq="Select ";
myq+=" C.* ";
myq+=" FROM ";
myq+=" CustomersTable AS C ";
myq+=" WHERE ";
myq+=" C.LastName='"+StringVarriableForLastName+"' ";
myq+=" AND C.FirstName LIKE 'A' ";
myq+=";";

when you have a big querry, I like to seperate it out on lines so I can comment out or re-arrange them later.
Apr 12 '07 #3
NiteshR
21
I find the best method is to use a string and break it into parts.

string StringVarriableForLastName="Plater";
string myq="";

myq="Select ";
myq+=" C.* ";
myq+=" FROM ";
myq+=" CustomersTable AS C ";
myq+=" WHERE ";
myq+=" C.LastName='"+StringVarriableForLastName+"' ";
myq+=" AND C.FirstName LIKE 'A' ";
myq+=";";

when you have a big querry, I like to seperate it out on lines so I can comment out or re-arrange them later.
Hi, this doesnt seem to work.
when i output the value from the variable 'myq', it shows me the coding text
as typed.
Apr 12 '07 #4
Plater
7,872 Expert 4TB
Are you actually in the dev-enivironment or in some sort of SQL Query creation zone?

what I typed would be place in your C# code section, if you were in a query creation zone, just type it out.
The output of my string should look like this

Select C.* FROM CustomersTable AS C WHERE C.LastName='Plater' AND C.FirstName LIKE 'A' ;
Apr 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
15
by: Douglas Garstang | last post by:
All, I posted a newsgroup question here a few weeks back, asking some questions that related to my 10 year quest (so far) to understand pointers. Someone suggested I write a simple emulator....
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
16
by: lovecreatesbeauty | last post by:
`Writing C code is very simple', one guy related to my work said. I'm not sure whether he is an expert or not. What he said about C programming like this can't convince me. I think there should be...
4
by: Gary Bond | last post by:
Hi All, Can anybody point me to some 'how-to' documentation, tutorials, etc as to how to write a shrink/protect wrapper for .Net exes/dlls, (like the Shrinkwrap product for instance). I have...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
89
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.