|
hi everyone I'm trying to not only make my cod emore readable but also reusable so i'm trying to rewrite the following bit of logic;
protected void Page_Load(object sender, EventArgs e)
{
clsDB = new clsDB();
GetSalesmanDesc();
if (!IsPostBack)
Populate_ddlCustomers();
}
public void GetSalesmanDesc()
{
salesmanList = new List<Salesman>();
try
{
salesmanList = new List<Salesman>();
con = new SqlConnection(strConnString);
SqlCommand com;
com = new SqlCommand();
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "GetSalesmanDesc";
com.CommandTimeout = 300;
com.Connection = con;
com.Connection.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Salesman salesman = new Salesman();
salesman.SalesmanID = reader["SalesmanCode"] as String;
salesman.SalesmanName = reader["Salesman"] as String;
salesmanList.Add(salesman);
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
I would really like to try and keep the SQL actions separate from my main procedure so instead of the above I am tryign something like this:
public void GetSalesmanDesc()
{
salesmanList = new List<Salesman>();
clsDB.getSalesmanDesc();
}
the code in clsDB.getSalesmanDesc() is:
public bool getSalesmanDesc()
{
com = new SqlCommand();
com.CommandTimeout = 300;
com.CommandText = "GetSalesmanDesc";
com.Connection = sqlCon;
com.CommandType = CommandType.StoredProcedure;
da.SelectCommand = com;
try
{
sqlCon.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Salesman salesman = new Salesman();
salesman.SalesmanID = reader["SalesmanCode"] as String;
salesman.SalesmanName = reader["Salesman"] as String;
salesmanList.Add(salesman);
}
return true;
}
catch (System.Data.SqlClient.SqlException Sex)
{
strDBErrorMsg = Sex.Message;
return false;
}
catch (System.Exception Ex)
{
strDBErrorMsg = Ex.Message;
return false;
}
finally
{
DestroyDatasource();
}
}
Can anyone help me out please?
|
|
|
|
|
Your impulse to separate data access and processing is a good one. It's hard to know what level of advice to offer here – depending on the application anything up to a full blown entity management framework might be the right answer.
Try passing salesmanList to the data access method you just pulled out, or having that method create and return the list.
Also, there's probably a one line Linq query you can run against the database to create this list (I'll leave that to one of our Linq gurus).
|
|
|
|
|
the application itself is a 1 page web app to allow a user to manage product/Salesman data in a gridview, nothing to special. I could rewrite the above bit of code t populate a dataset and use that to populate the ddlSalesman, I'm just wondering how I would do it using the exisiting List that I have created?
|
|
|
|
|
Hello All,
I am developing a Windows Application using C#.
I have set the Gujarati font as the font Property of the TextBox.
When I am trying to store the data in the Database at that time it returns the English Characters. Means it displays the data in Gujarati but when I am trying to store data it returns english..
I have typed something in Gujarati and when i am taking the value it returns the English in code behind..
objGujarati.Name = TextBox1.Text.Trim();// This statement returns english..
also i want to store the Gujarati data in SQL Serevr by using the stored procedure.
Please anyone help me, i am stuck in my work.
Thanks in Advance,
Rakesh Gupta
|
|
|
|
|
Make sure the encoding for the database is set to UTF8 (or some other unicode format). Older database providers default the encoding to ISO-8859-1 (i.e. 256 character ANSI).
|
|
|
|
|
Okay..
Thanks but right now its not my problem.
My Problem is the that returning from the text box is Gujarati.. As i have typed Gujarati thought it returns English..
|
|
|
|
|
The font does not change the content, it only makes it look differently. When you display the text in Wingdings, hardly anyone will be able to read it. Looks like your Gujarati font does something similar like the Wingdings font.
Rather change the input method such that you get Gujarati characters, the .NET Textbox will handle them automatically because it uses Unicode.
|
|
|
|
|
Hi all,
Please I am trying to generate income statement and balance sheet with data from sql using C#. Is there an easy way to go about this, as gridview does not give me the report in the right format. Many thanks.
|
|
|
|
|
Pull the SQL data, iterate the result set and build a custom HTML output and push to a webbrowser control or write out to file as HTML or via a pdf writer.
Just one option!
|
|
|
|
|
dondrey wrote: Is there an easy way to go about this
In general - no.
If you can pull data, regardless of the business use, and display it any way you want then that is easy because there are no restrictions.
Once you add restrictions then your output must conform to those restrictions. The more restrictions the more involved it becomes (not necessarily more complex but complexity could enter into it as well.)
This is why software specifically for reporting exists. Such software isn't necessarily easier than doing it yourself but with more complex reports and with an increasing number of different types of reports learning such a system is probably a good idea. Whether you need it however depends on your (business) current and future needs.
|
|
|
|
|
Actually my task is create a structure to the mails, store those mails into a file(like pst file) i dont have any idea about this. if anybody know this. please help me
i am getting mails from mail server but i dont know. how to create a Structure and how to create file (like pst file)using c#.net
Saikumar
|
|
|
|
|
Since this is a single user app, look at creating a SqlCE database - it is built in to .NET so it needs no special installation, and it can provide all the structure you will probably need.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: SqlCE database - it is built in to .NET
Ummm, no it's not. SQL Server Express Edition is installed with Visual Studio.
If you write an application with it you have to install SQLCE on the client machine seperately from the .NET Framework.
|
|
|
|
|
Your manager has asked you to do this? If so you should tell him that you need help since you've not done this before. Never ceases to amaze me when managers hand out work without knowing whether or not the recipient can actually do the work!
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Error 2 No overload for 'HookManager_MouseClick' matches delegate 'System.Windows.Forms.MouseEventHandler'
|
|
|
|
|
So why are you not asking whoever wrote the "HookManager" library about this??
|
|
|
|
|
Hai there guys...i'm new here in c# development so I really hope to get some pointers here and there.
So basically what I'm working now is to insert and display the data in dataGridView. I've already done one and it works fine but i wanna refine it. Currently when the application is run it will display all the data that had been stored in the database which can make it confusing for user when they inserted new data, then when they wanna check their data, they have to scroll all the way to find their data that had just been inputted.
So now what i wanna do is to adjust the application so that every time the user run the application, the dataGridView will display an empty view of the table which they can insert their data peacefully without needing to worry about other people data.
(all this using a single table.)
so any idea guys??because i don't even know how to start...
|
|
|
|
|
shahrulnizam wrote: they can insert their data peacefully without needing to worry about other people data.
In your database table create a field for the user ID. Then set the BindingSource.Filter property to the current userID, so that the DataGridView displays only the records pertaining to the current user. While adding the new row, using DataGridView.RowsAdded event set the userID filed of the new row to the current userID
|
|
|
|
|
where to set the bindingSource.filter??it's not at the properties window..
|
|
|
|
|
|
Hi All,
I have done lot of java work for more than 8 years. But I am new to C#. I am writting a client to the Simple Application. For that Client I need to add header..
Here is the scenario...
Server SIde code is written in Java and exposed as Web service.
Client SIde is Written in .Net/C#. I need to access that webservice.. And I am sucessful. Now I need to add a header so I can pass *ID* 122344*/ID* through soap Header. Can some one suggest me , How to do that.. I have been strugulling on this for more than 3 days..Any help really appreciated.
|
|
|
|
|
If you derive a class from your web service reference, you can override the method GetWebRequest . At this point, you can add your own headers through the Request object.
|
|
|
|
|
Hi Folks,
Does anyone have a good starting point for information on reading RF signals using C#? I have an electric smoker (ie. BBQ Pit) that has an RF remote that displays different temperatures and I would like to write an application that would allow me to control the remote functions from my PC instead of from the remote.
I'm sure I would need to purchase an RF Receiver such as this one[^] which I will if I can figure out that this is possible!
|
|
|
|
|
I don't have a guide to point you at, but he first thing you need to find out is what frequency the transmitter on the smoke is using. Then you can make sure you get a RF transceiver that can handle it.
The next thing is determining if there is any protocol that is being used to transfer application-level data, if any.
After that, determine the format of the data coming from the smoker so you can get the correct temperature. Then what are the commands you send back to the smoker to do what and what is the format of those commands??
If you can't find documentation on any of this stuff, you're going to find it extremely difficult to do this from your code.
|
|
|
|
|
Thanks for the info Dave!
I search for the FCC ID on fcc.org and found a lot of information about the module and its communication methods. The handheld remote unit contains a 433 Mhz transceiver - is there something more specific than that I should try and find out related to the frequency, or should any 433 Mhz transceiver be able to communicate with it (depending on the protocol as you mentioned)?
As you said, I'm sure it will be extremely difficult to figure this out without any documentation - but I think if I can get a transceiver and get the communication going between the two then I can figure out the functions (again, there is a lot of info on the FCC site).
Do you know sort of what the process would be for communicating with the transmitter on the smoker would be? I guess I would ideally have a USB transceiver so once it was installed I guess you would just use the USB API to communicate with it as a HID, right? (I know that is oversimplifying what could be a painful process) Is there a process of "pairing" devices a la bluetooth or do these types of things work more off of just responding to any frequency that matches what it's looking for?
|
|
|
|