DataSource Controls :: How To Convert, The Code To Query A SQL Database Using A DSN-less Connection
Sep 10, 2010How do we convert, the following code to query a SQL database with ASP using a DSN-less connection
[Code]....
How do we convert, the following code to query a SQL database with ASP using a DSN-less connection
[Code]....
select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid
View 5 Replies<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$appSettings:ConnString%>"Â SelectCommand="sql query ............."
This is in design and with the above I have
 SqlDataSource1.SelectCommand = "sql query ............. " in code behind
but if i have the connection in code behind. How do I execute
SqlDataSource1.SelectCommand == "sql query ............. "
It without any reader or dataset...
how to convert this AccessDataSource to a SqlDataSource connection?Thanks.CodePrivate Function GetNotes(ByVal id As String) As Object
Dim ds As New AccessDataSource()
ds.DataFile = AccessDataSource1.DataFile[code].....
I want to use from two db connection in one linq query
My sample is:
int a=1;
if(a==1)
DataClasses1DataContext1 db = new DataClasses1DataContext1();
else
DataClasses1DataContext2 db = new DataClasses1DataContext2();
var q =
from c
in db.F_Groups
select c;
In this code a=1 so db connection is DataClasses1DataContext1
I want if a=2 then db connection = DataClasses1DataContext2
but this code is error.
db connections is completely same but in two deferent class a db connection is sql and another is oracle
How can I convert this sql query to LINQ ?
[code]...
I am having problem in diffrentitate error between internet connection loss error and Other Error in query for example: duplicate record found.
Both the error fall into System.Data.SqlClient.SqlException category.
But the way to handle both this 2 error is different.For connection error , i need to bring user to connection loss page while for duplicate record found error, i need to show the user a pop up.
Unless i do a checking exactly on the error message , else i have no ways to differentiate connection loss error and any other error. Am i correct for this?
I am using DATAPART(..) function in SQL to query table. Now I have Day of the year which I want to convert to actual date and then return Here is the query
[Code]....
For the moment I am returning day of the year, but I want to return date (current year can be assumed). Therefore I have two pieces of information1) day of the year2) year it selfExample day of the year = 125 and year = 2010 How to convert this to date in SQL
By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.
View 10 RepliesI succes with this code
if (InitDateStart.Text != "" && InitDateEnd.Text != "")
{
strWhere += "And ((Convert(DateTime, InitDate, 105) >= Convert(DateTime,'" + InitDateStart.Text + "', 105)) And (Convert(DateTime, InitDate, 105) <= DateAdd(day, 1, Convert(DateTime,'" + InitDateEnd.Text + "', 105))))";
}
How do I do this code as a parameterized query ??I tried this but with no succes.I got some strange result by this
strWhere += "And Convert(varchar(10), ServiceInitDate, 105) >= @InitDate............. ";
GridDatasource.SelectCommand += strWhere; [code]...
IEnumerable<DataRow> query = (from obj1 in objeDC.tmpPolicyRenewals.AsEnumerable()
where obj1.AgentCode == "Admin"
select new
{
obj1.Product,
obj1.PolicyNo,
obj1.Insured,
obj1.EffDate,
obj1.ExpDate,
obj1.GrossPrem,
obj1.Status
}) as IEnumerable<DataRow>;
Getting null value. whats error ?
I would like to ask the programmers to help me in C# with LINQ to SQL.
I have this code conn.Open();
SqlDataReader dr = DB.ExecSpReader("select AttachmentName from AttachmentTable where TicketId=" + ticketID, param);
while (dr.Read())
{[code]....
and I need to convert it to LINQ SQL.
I'm having a problem, which I haven't had with other projects, in setting up membership. I have set up a aspnetdb database using the asp.net confirguration tool. The database is in the app data folder and I can set up users and roles etc from the web site administration tool. However, trying to log in within the application, using the login control I get "Login attempt was not successful".
I have noted the following :-
1. On the home page of the Web site administration tool the application:/ shows no application where as normally it would show the name of the application.
2. Clicking the AspNetSqlProvider test button, I get the error "could not establish a connection to the database"
3. Although various lines have been added to the web config file, no connection string has been created to the aspnetdb file in the app data folder.
4. If you right click on the aspnetdb file within the solution explorer, there is an option of "include in project". Selecting this doesn't however solve the problem.
I'm trying to weigh up which is the better most reliable database connection for use on a vb.net/ms sql site. I've previously experienced problems catching and closing db connections with the using statement if an error occurs, but do like the fact it doesn't need to use any global variables. Both examples use a general Database class file which opens and closes a connection.my current examples are: TRY CATCH EXAMPLE:
[Code]....
[Code]....
convert the query in pic #3.
pic #1 is where the user will put the 3 fields.
pic #2 is the involved tables and data that we already tried, it works, but only through sql, how can we make the formula where datagrid will show the results.
1. http://i1188.photobucket.com/albums/z403/hell91131/8udh1nd12e2.png
2. http://i1188.photobucket.com/albums/z403/hell91131/wqrfefcwerfewf.png
3. http://i1188.photobucket.com/albums/z403/hell91131/qewrfewfewrgferge.png
I try to connect my database for so long so i wrote two type of codes. Let's discuse first on.
I have database called PhoneDirectory.
It have only one table named Residents.
I have button wiht ID="Button1".
I want when i click this button to see all of my residents.
I want to see the result in DetailsView and to be able to edin, delete and add new resident.
First try with SqlDataSource so i wrote this:
<asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
i am using sqlserver 2008
in my computer, sql server name is "LOCALHOET-PC" AND SECOND ONE "LOCALHOST-PCSQLEXPRESS"
I have write a code in my software like
SqlConnection conn;
conn = new SqlConnection("Data Source=LOCALHOST-PC;Initial Catalog=n4netsALT;Integrated Security=sspi");
conn.Open();
and it is working working smoothly in my computer
My website is working but when I host it up, the connection are all screw up. Is it because my connectionString are all linked via SqlDatasource and is for local files only? Whats the coding that I need to put in so that my site will connect to the database via accessing the web.config or server?
View 11 RepliesI am designing a web application and have separate layers for UI, BAL, DAL and DB, while using custom business objects and collections. The app will be used by over 10,000 + registered used and it becoming more complex as I add new functionality such as inline editing and batch processing of collections with transactions ... which has me up late at night trying to design the best approach for this ...In some UI web forms, I bind say 3 controls to 3 different collections. The UI calls the BAL classes for the required collections, then binds the collection returned. So for each collection I want, a db connection is opened and closed. As I understand database connectivity adds overhead so Is there anyway I can design this so 1 database connection is created for a unit of work in a 3-tier or n-tier architecture?
View 7 RepliesIs it mandatory to close database connection in enterprise library 4.1?
View 1 Repliesam writing a series of WSS/MOSS webparts amongst which one will need to detect the current SQL Server database connection, prompt the user to setup a new connectionstring, and fire appropriate stored procedures to create a new database if needed. The user needs to be presented a textbox or label control with the current database connection. I've never had to detect current database connection, what methods do I call for this? If the desirable connection is not present, the web application needs to prompt the user to make a new database. The user really won't make the database, they simply need to click the command button which will fire the stored procedure to create the database.
View 1 RepliesI have been looking for a way to convert C# datatype into database specific type of MS SQL. For example when I do [Code]....
I would get System.GUID or something like that but what I want is UniqueIdentifier instead of System.GUID. In most cases, I would also want the length of the type like varchar(1000) and stuff like that. Is there anyway I could convert or get similiar result ?
First off, I am just getting started with ASP.NET so I expect this is something that I am doing.
i am trying to make a connection to a MS SQL database on my local machine.
I have the following in web.config
[code]....
how to query the system date in selectcommand in gridview without using the codebehind. using c# .net
my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM tablename where date_today = <SYSTEMDATE>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName
%>"
I am selecting time from dropdownlist. and want to convert it in datetime and store it in database. When I am converting it to Datetime using following statement.
DateTime start_Time = Convert.ToDateTime(start_ts);
but it is showing as : date:12:00:00AM