|
I know, that there must be a possibility not to usee the com interface, I have seen it, but do not know, how they do it
|
|
|
|
|
If there is, I've never seen nor heard of it.
|
|
|
|
|
have you guys who a very very familar with that stuff to check?
|
|
|
|
|
dataaccesslayer
public SqlDataReader reader(string query)
{
try
{
con1.Open();
cmd = new SqlCommand(query, con1);
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
con1.Close();
}
return dr;
}
logical layer
public SqlDataReader Product_Gridclick(string id)
{
query = "select pid,pname,pmodel,pprice,sprice,discount,pdescription from product_table where pid=" + "'" + id + "'";
return da.reader(query);
}
presentation layer
string s = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
SqlDataReader dr;
dr = llayer.Product_Gridclick(s);
if (dr.HasRows)
{
while (dr.Read())
{
txtproductid.ReadOnly = false;
txtproductid.Text = dr[0].ToString();
txtproname.Text = dr[1].ToString();
txtpromodel.Text = dr[2].ToString();
txtpurprice.Text = dr[3].ToString();
txtsaleprice.Text = dr[4].ToString();
txtdiscount.Text = dr[5].ToString();
rchdescription.Text = dr[6].ToString();
}
}
Gnanavel Sekar
|
|
|
|
|
The finally in reader closes the connection. This happens before this method returns, so you are opening and closing the reader before you attempt to iterate over the reader.
|
|
|
|
|
Suggestions:
- Create all Sql***-objects only locally (in methods), don't have variables for them as class members. Pass them as arguments to other methods if needed.
- Use all disposable Sql***-objects in using-blocks.
- Don't use Sql***-objects anywhere but in your DAL. Use DataTables/DataSets or POCOs to transport the data between your layers.
- Use SqlParameters instead of concatenating your query strings with values.
(By Sql***-objects I mean SqlConnection, SqlCommand, SqlDataReader etc.)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha is right on all his points:
Your Data layer should be the only one which even knows of the existence of SQL your Business Layer (that you called the Logic Layer) should have no idea about SQL or DataAdapters - that way if you need to change from SQL Server to Access, or MySql or even a text file, the changes are localised to the Data access layer and don't impact any other area.
SQL objects are scarce resources, and you need to ensure that they are Disposed correctly. a using block is the best way to do this as it removes the variable whenever it goes out of scope. You can't return a DataReader from your reader code because the connection has been closed - and a DataReader needs the connection open until you have finished reading the records. Consider using a DataTable instead.
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Your business layer should probably be converting DataTable objects into collections of logical class object instances so that the BL can work with "sensible" objects instead of having to rely on the order of columns in a datatable (or worse a datareader as in your code). Certainly, your presentation layer should be working with "abstract objects" instead of anything like the actual raw data.
Setting the value of a textbox inside a loop will only give you the last row in the datareader - so if you are only getting a single row, use
if (dr.Read())
instead of
while (dr.Read()) It's a lot more obvious what you intended to happen. In this case, I'd want to check that there was only one such item - and log or report a problem if there were more or less.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello,
i need to build an Audiometric chart like this in c# .net 4
Audiometric chart
x values are: 125, 500, 1000, 2000, 4000, 8000
Consider that the series can have intermediate values, example 750, 3000, 6000.
i tried to use Datavisualization library, i suppose that values are logarithmic but I could not find the correct values.
here's the code
public MemoryStream DrawChart(double baseValue)
{
Chart chart = new Chart
{
Palette = ChartColorPalette.EarthTones,
Width = 1200,
Height = 800,
ForeColor = Color.Black,
BackColor = Color.White,
BorderlineDashStyle = ChartDashStyle.Solid,
BackSecondaryColor = Color.White,
BackGradientStyle = GradientStyle.None,
BorderWidth = 0
};
Series series = new Series("Right")
{
Color = Color.Red,
LabelForeColor = Color.Black,
ChartType = SeriesChartType.Line,
IsValueShownAsLabel = false,
XValueType = ChartValueType.Int32,
YValueType = ChartValueType.Int32,
MarkerStyle = MarkerStyle.None,
XAxisType = AxisType.Primary,
YAxisType = AxisType.Primary,
};
series.BorderWidth = 6;
series.SmartLabelStyle.Enabled = true;
series.Points.AddXY(125, 0);
series.Points.AddXY(250, 0);
series.Points.AddXY(500, 10);
series.Points.AddXY(1000, 120);
series.Points.AddXY(2000, 10);
series.Points.AddXY(3000, 0);
series.Points.AddXY(4000, 10);
series.Points.AddXY(6000, 10);
series.Points.AddXY(8000, 20);
chart.Series.Add(series);
ChartArea area = new ChartArea("Default")
{
BorderDashStyle = ChartDashStyle.Solid,
BackSecondaryColor = Color.White,
ShadowColor = Color.Transparent,
BackGradientStyle = GradientStyle.TopBottom,
BackColor = Color.Transparent,
};
area.AxisY.Minimum = -10;
area.AxisY.Maximum = 120;
area.AxisY.IsReversed = true;
area.AxisY.Interval = 10;
area.AxisX.IsLogarithmic = true;
area.AxisX.IntervalType = DateTimeIntervalType.Number;
area.AxisX.IntervalOffset = 0;
area.AxisX.IntervalOffsetType = DateTimeIntervalType.Auto;
area.AxisX.LogarithmBase = baseValue;
Title titleObj = new Title
{
ForeColor = Color.Black,
Text = "Audiometry",
};
if (area.AxisX.IsLogarithmic)
{
titleObj.Text += " logarithmic base " + area.AxisX.LogarithmBase;
}
chart.ChartAreas.Add(area);
chart.Titles.Add(titleObj);
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
MemoryStream stream = new MemoryStream();
chart.SaveImage(stream, ChartImageFormat.Png);
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
|
|
|
|
|
Hello ,I want to generate crystal report to generate invoice using two tables CustomerOrder and OrderDetails..please help on how to handle multiple tables in crystal report
|
|
|
|
|
you could use a stored procedure that joins multiple tables
|
|
|
|
|
I am fairly new to programming and am maintaining a legacy web application.
Need to access a checkbox value and send it via email built in the same aspx page using C# code.
Here is the code. Any help on this will be much appreciated.
<pre lang="c#">
emailBody +="<tr>";
emailBody +="<td align='right' width='10%'><FONT face='Verdana' size='1'> Do you have any active MTY billing?: </FONT></td>";
emailBody +="<td width='20%'><FONT face='Verdana' size='2'> " + chkValue + "</FONT></td>";
emailBody +="</tr>";
<td colspan="4">
<input type="checkbox" name="Yes" id="chkYes" value="" onclick="alert('Do something');"/><B><FONT size="1" face="Verdana"> Yes </FONT></B>
<input type="checkbox" name="No" id="chkNo" value=""/> <B><FONT size="1" face="Verdana"> No</FONT></B>
</td>
|
|
|
|
|
I think you should be using radio buttons instead of check boxes because checkbox is for multiple options. Anyways since you are using html controls in page I suggest you use jQuery code to update a hidden field value and read the same from C# code.
In your html code near checkboxes/radiobuttons add this
now in your javascript write the following code function which is called on checkbox checked event.
JavaScript/jQuery
==============================================================
function CaptureAndUpdate(val)
{
if(val.checked==true)
$('.hdn_checkBoxResult').val(true);
else
$('.hdn_checkBoxResult').val(false);
}
your html checkbox becomes
==========================================================
Rajesh K
|
|
|
|
|
Thanks for the response..
I also have few other hidden inputs in the same page and they work fine.
As per your suggestion:
1) Added radio buttons instead of checkboxes.
2) Added hidden input field hdn_checkBoxResult.
3) Called a function to check if the value of radio button is true, if so, then assign value to hdn_checkBoxResult.
4) Appended hdn_checkBoxResult.Value in the email.
Is there anything else I am missing?
The email still doesn't show the selected radio button value.
Here is my code:
..............................................................................................
<td colspan="4">
<input type="radio" name="rdoCheck" id="rdoYes" value="" onclick ="theChecker(val)" />
<b><font size="1" face="Verdana">Yes </font></b>
<input type="radio" name="rdoCheck" id="rdoNo" value="" />
<b><font size="1" face="Verdana">No</font></b>
</td>
Have declared this hidden input field outside the table.
<input type="hidden" runat="server" id="hdn_checkBoxResult" name="hdn_checkBoxResult" />
function theChecker(val)
{
if(val.Checked ==true)
{
$('.hdn_checkBoxResult').val(true);
alert('alert msg');
}
else
{
$('.hdn_checkBoxResult').val(false);
}
}
emailBody +="<tr>";
emailBody +="<td align='right' width='10%'><B><FONT face='Verdana' size='1'>Question ? </FONT></B></td>";
emailBody +="<td width='20%'><FONT face='Verdana' size='2'> " + hdn_checkBoxResult.Value + "</FONT></td>";
emailBody +="</tr>";
modified 18-Jun-15 15:29pm.
|
|
|
|
|
Are you using asp.net control for submitting the form ?
If yes then use asp.net radio buttons for capturing values of 'Yes' or 'No'
as follows replace the html controls with asp.net controls.
If no then use asynchronous call to call the WebMethod in page and send values as bool or string.
|
|
|
|
|
Thanks RajeshKasani it works now.
|
|
|
|
|
I have some strings to represent the names of forms and controls.
for example;
MenuLogin = name of an instance of System.Windows.Forms.MenuItem
Now I want to assign Text value to the object whose name is the string at run time.
I.e:
s1 = "MenuExit"
Object(s1).Text = Exit login window //find an object,Name:MenuExit
I can't find a method in the Object that can search an object with name "MenuExit" in the application.
Please tell me how to implement it, thanks.
modified 17-Jun-15 15:29pm.
|
|
|
|
|
Are you wanting to know how to do this in C#?
|
|
|
|
|
Sure, Thanks.
I rewrote my question. In fact, I don't want to create a new object,
I just want to find the object with the name: xx-YY.
|
|
|
|
|
I try to use Assembly.GetExecutingAssembly().
Thanks
|
|
|
|
|
I think you misunderstood Pete's comment, this is a C# forum, and your question is Visual Basic. There is a designated forum for VB questions.
As for your question; I'm not entirely sure what you want, WinForms are not my expertise. It seems like the .Text method does not exists in s1.
|
|
|
|
|
econy wrote: I can't find a method in the Object You annot assume that Object will contain such a method; and where would it search for these items? You would need to first create some type of List that contains all the Objects, which you then search by name.
|
|
|
|
|
Hello,
i want use an external Method there will be get an Struct.
The Struct is lokk like this:
typedef struct _SYSTEM_POWER_STATUS {
BYTE ACLineStatus;
BYTE BatteryFlag;
BYTE BatteryLifePercent;
BYTE Reserved1;
DWORD BatteryLifeTime;
DWORD BatteryFullLifeTime;
} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;
In C# it looks like this:
struct SystemPowerStatus
{
byte ACLineStatus;
byte batteryFlag;
byte batteryLifePercent;
byte reserved1;
int batteryLifeTime;
int batteryFullLifeTime;
}
So, i want to rename the Fields. How i can do it? must the Structs Fields named like the original Struct?
Best regard
Armin
|
|
|
|
|
The field names don't matter. So if you're writing a struct, you can choose any names you like. A smart developer would have simply tried it; you learn more that way.
|
|
|
|
|
Piebald is right - the names are irrelevant.
If you want to "match" the two structures though, then that's probably because you are planning on sending or receiving them from / to an external unmanaged application of DLL. If so, you have to ensure they are identical in layout: so add a StructLayout Attribute[^] to your C# version to force the compiler not to optimise the memory.
In this particular case, it's probably irrelevant (as there are four bytes before the first 32bit number) but that isn't always the case.
It's worth checking if this site has a structure that is compatible ready for use: http://pinvoke.net/default.aspx/Structures/SYSTEM_POWER_STATUS.html[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If you're using Windows Forms, you don't need this structure, or the P/Invoke method; the SystemInformation.PowerStatus property[^] will give you the same information.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|