|
I Do't have any Connection. I have data in dataset.
If you can think then I Can.
|
|
|
|
|
SqlDataAdapter daMyTable = new SqlDataAdapter("SELECT * FROM myTable", con);
SqlDataAdapter daMyOtherTable = new SqlDataAdapter("SELECT * FROM myOtherTable", con);
SqlDataAdapter daJoined = new SqlDataAdapter("SELECT * FROM myTable INNER JOIN myOtherTable ON myTable.iD=myOtherTable.iD", con);
I am curious why did you get the data seperately instead of using a one query with a "join", getting all the data all once and bing it to gridview?
|
|
|
|
|
Purely to show what I was doing, and that I had two tables in the database.
Seemed worth doing for a beginner in this stuff...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
just use innerjoin ..
select Emp.*, Dept.* from Emp inner join Dept on Emp.Emp_No = Dept.Emp_No
|
|
|
|
|
How can i use join in data set.
If you can think then I Can.
|
|
|
|
|
In case of Database connection we have two options to close the connection is Close and Dispose.
Both are working same and Fine.
So Pls describe it which one is sutaible for database connection close. and what is the diffrence between Close and Dispose.
Thanks
If you can think then I Can.
|
|
|
|
|
You should use Close. Dispose method automaticly is called by a garbage collector. Usaly when using WinAPI you use CloseHandler api and other to clear a memory when not needed. This also prevents memory leaks. Dispose method is inherited from IDispose interface.
|
|
|
|
|
Dispose. Or (for tidiness) Close and Dispose - though the close is done automatically as part of the dispose.
In preference, enclose your conection and commands in using blocks which will automatically dispose the objects and remove them from scope.
using (SqlConnection con = new SqlConnection(...))
{
con.Open();
using (SqlCommand com = new SqlCommand("SELECT ...", con))
{
...
}
} Closing does not free up all resources associated with the connection until it is disposed, which may take some considerable time if you are waiting for the Garbage Collector to be triggered.
You would normally Close the connection if you will reopen it again soon.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Theoretically, you're right. But in my company we had some troubles, when we used construct you're suggesting. The problem was, that connection wasn't always closed, when enclosed in using. So we are using construction as below:
using (SqlCommand command = new SqlCommand())
{
using (command.Connection = new SqlConnection(connectionString))
{
try
{
command.Connection.Open();
}
catch(Exception)
{
}
finally
{
command.Connection.Close();
}
}
}
And concerning the question... link[^]
It says, that "Close and Dispose are functionally equivalent". Therefore I think you should use Close rather, than Dispose. It makes code easier to read, because you can see the pair of methods: Open - Close, and you know, that they're connected to each other.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Close allows you to open the connection again.
|
|
|
|
|
thanks sir...
If you can think then I Can.
|
|
|
|
|
Dispose calls Close.
Which would seem to mean Dispose should be fine.
However, Close can throw exceptions.
So what happens in the following code if Close throws an exception? Myself I expect the insert to have succeeded (if it didn't throw an exception and transactions are not used.)
using(connection...)
{
}
Additionally there is no assurance that Dispose will not throw an exception for some other origination besides Close as well.
Given that database operations are often critical I consider that some variation of the following is often a better idiom.
connection = ...
bool isOk=false;
try
{
isOk=true;
}
finally
{
try
{
connection.Close();
}
catch(Exception ee)
{
if (isOk)
{
}
else
{
}
}
try
{
((IDisposable)connection).Dispose();
}
catch
{
}
}
You could also decide to handle Out Of Memory exceptions and thread abort as well.
|
|
|
|
|
|
PIEBALDconsult wrote: Paranoid much?
Somewhat above a smidge.
|
|
|
|
|
how to develop mobile application in c#?
modified on Thursday, March 10, 2011 12:57 AM
|
|
|
|
|
Write Ur Question properly Accourding to Form Type.
If you can think then I Can.
|
|
|
|
|
I'm guessing you weren't when someone posted this question.
"You get that on the big jobs."
|
|
|
|
|
Start with Google for "mobile c#" and go on from there.
I must get a clever new signature for 2011.
|
|
|
|
|
|
I'm working on an events page that presents a list of events and when an event is selected the details of the event are presented on another page. The event details page is querying the details of the event from an SQL DB field. I'm writing the details with response.write and since its all wrote with html tags its presents properly. The issue I am having is when I throw a function into the field text string and attempt to write it, I just get the string.
SQL DB field contains something like the below
<h1>Event Name</h1><p>Details</p><% PRESENTMEMBERS(); %>
Is it possible to execute <% PRESENTMEMBERS(); %> via response.write or some other method?
|
|
|
|
|
Maybe. Need more information.
|
|
|
|
|
<
I have setup a DataSet with DataTables in a separate project in which I inialize and load it separately.
public class DataSetA
{
public Trial trial;
public DataSetA()
{
this.trial = new Trial();
}
}
Then when I wish to access the data in another class I use the following I get the following error message "Object reference not set to an instance of an object."
public static class Test
{
public static DataSetA dsA;
static void GetData()
{
Int32 nData = Trial[nRow].nData()
}
}
Can I do the above or do I need to load the DataSet through the constructor as follows.
public class Test
{
public DataSetA dsA;
public Test(DataSetA dsA)
{
dsA = new DataSetA()
}
void GetData()
{
Int32 nData = Trial[nRow].nData()
}
}
If it is a static class I can not do the above.
If alternative methods when do I use the necessary methods.
>
I appreciate any help you can give me.
Thanks in advance,
Michael
|
|
|
|
|
I want to get sender's email address from AppointmentItem.
But I can't find any property about sender's address.
If i get sender's address , i want to edit sender's address.
Is it possible?
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
use the following peocedure to retrive the outlook user email address
String temp;
Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
temp = message.UserProperties.Session.CurrentUser.Address.ToString();
string temp will contain the outlook user emial address.
I have tried this code for outlook 7 and is working fine.
help each other to make this world a better place to live
|
|
|
|
|
Hello Everyone,
How to generate 2 digit numbers randomly in every 20 minutes and save that numbers into database in every interval also.....
How to achieve this? Can anyone give me a solution soon.
Thanks
|
|
|
|