|
you should download Sams visual c # 24 hour learning Ebook,from Torrentz.com...it will help you...because i am using this book to study c #
|
|
|
|
|
nidobeb wrote: you should download Sams visual c # 24 hour learning Ebook,from Torrentz.com... Or you could buy it or borrow it from your local library.
/ravi
|
|
|
|
|
you should download buy Sams visual c # 24 hour learning Ebook,from Torrentz.com a reputable source ...it will help you...because i am using this book to study c #.
|
|
|
|
|
Voted to remove for poster's own good ... putting an email in a post is dumb. And yes, buy a book. This is not a site of free teaching staff.
|
|
|
|
|
|
Seconded. It should be compulsory reading for all .NET developers.
Regards,
Rob Philpott.
|
|
|
|
|
|
Book, school, or google. Take your pick.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
namespace new_form_app
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ }
}
protected void previewButt_Click(object sender, EventArgs e)
{
}
protected void submitButt_Click(object sender, EventArgs e)
{
string M1 = TextBox1.Text;//nak ambil data dari textbox
string M2 = TextBox2.Text;
string M3 = TextBox3.Text;
string M4 = TextBox4.Text;
string strsql = String.Format("insert into NewForm values('{0}','{1}','{2}','{3}')", M1, M2, M3, M4);//ambil value dalam variable M1,M2,M3,M$ dan diberi kepada {0},{1},{2}
//,{4}
OleDbCommand dbComm;//register kepada oledbcommand
OleDbConnection dbConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);//intiallize
dbComm = new OleDbCommand(strsql, dbConn);//initialize utk dbcomm
dbConn.Open();//open conn
dbComm.ExecuteScalar();//execute sql command
dbConn.Close();//close conn
Response.Write("Successfull");
}
protected void clearButt_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
}
}
|
|
|
|
|
|
how want to preview my web application
|
|
|
|
|
First edit your post to properly format your code snippet.
Second, edit you post to actually ask a question.
You will find the responses you receive are related to the effort you put into the post and how well you comply with the guidelines here.
I know the language. I've read a book. - _Madmatt
"The OP herself was not sure about her question"
"The OP is from India and I know what she meant." - Shameel
|
|
|
|
|
To start, try giving the subject heading of your post something meaningful. Just the fact that your posting a question would suggest you are looking for help.
Here is a list:
You have unused using statements, they should be removed.
Don't use underscore _ in namespaces. Try something like Daniel.NewFormApp
Don't start class names with underscores, start with a capital letter.
Code isn't formatted, when posting at CP enter code inside "code block" tags
Don't leave empty methods in your code, previewButt_Click
Give variables meaningful names like NameTextBox, not TextBox1
Pascal/camel case variables strSgl not strsql
Don't use "" as you are creating strings in memory for no reason, use string.Empty
clearButt and submitButt are probably not a good choice of naming, try something like ClearButton
And actually asking a question will help, we're not all engineers.
Other than that, it looks good
"You get that on the big jobs."
|
|
|
|
|
RobCroll wrote:
And actually asking a question will help, we're not all engineers mind readers.
FTFY
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
This method return "StackOverflowException" error for some inputs;like 12.
where is Infinite loop point?
public void cycle(int f){
int i, j;
if (f == 0)
return;
else
{
for (i = f; i >= 0; i--)
{
for (j = 0; j <= 10; j++)
{
if (i == Math.Pow(2, j))
{
f = f - (int)Math.Pow(2, j);
switch (j)
{
case 1:
cbx1.Checked = true;
break;
case 2:
cbx2.Checked = true;
break;
case 3:
cbx3.Checked = true;
break;
case 4:
cbx4.Checked = true;
break;
case 5:
cbx5.Checked = true;
break;
case 6:
cbx6.Checked = true;
break;
case 7:
cbx7.Checked = true;
break;
case 8:
cbx8.Checked = true;
break;
case 9:
cbx9.Checked = true;
break;
case 10:
cbx10.Checked = true;
break;
}
break;
}
}
}
cycle(f);
}
}
|
|
|
|
|
Hi,
1.
at the very bottom of your cycle() method is a call to method cycle(), so when all the i,j combinations make your test
if (i == Math.Pow(2, j))...
fail, your method calls itself with the same input value, clearly ending up in an "infinite loop". This will happen for the majority of f-values, as most numbers simply aren't a power of 2.
2.
I don't know why you would want to call cycle again; it is even unclear to me why you would need two for loops. And if your supported input range is limited (as the presence of a switch construct suggests), you also !! don't need a switch !!
I think the code below would come close to what you want (it also clears some checkboxes, something your code didn't do at all):
void myBinaryCheckboxes1(int f) {
cbx1.Checked= (f & 0x0001)!=0;
cbx2.Checked= (f & 0x0002)!=0;
cbx3.Checked= (f & 0x0004)!=0;
cbx4.Checked= (f & 0x0008)!=0;
cbx5.Checked= (f & 0x0010)!=0;
cbx6.Checked= (f & 0x0020)!=0;
cbx7.Checked= (f & 0x0040)!=0;
cbx8.Checked= (f & 0x0080)!=0;
cbx9.Checked= (f & 0x0100)!=0;
cbx10.Checked=(f & 0x0200)!=0;
}
BTW: in binary (and in many other situations), things would get numbered starting by zero (so cbx0 up to cbx9).
3.
For the really advanced implementation, you could further simplify if you would have a collection (array, list, whatever) holding those checkboxes; it would suffice to put them in their own GroupBox (nothing else in that GroupBox is easiest). And then have the checkbox tags hold their bit value (the hex numbers in the above code). The final code could then be as simple compact as:
void myBinaryCheckboxes2(int f) {
foreach(Control c in myGroupBox.Controls) {
((CheckBox)c).Checked=(f & (int.Parse((string)f.Tag)!=0;
}
}
BTW: If that looks too weird/convoluted, just stick with the code in myBinaryCheckboxes1() !
[ADDED] Note 1, triggered by lukeer's reply: depending on how the Tag gets assigned, one might not need the int.Parse, one could just assign a numeric tag right away, then use ((CheckBox)c).Checked=(f & (int)f.Tag)!=0; [/ADDED]
Luc Pattyn [My Articles] Nil Volentibus Arduum
modified on Tuesday, August 23, 2011 8:11 AM
|
|
|
|
|
1.you said "your method calls itself with the same input value" but if if statement become true f-values will change;line before switch.
2.I explain this with my sample:12
with input 12 first loop check from 12 till down until 8.At 8 when j become 3 at second loop (second loop prepare all possibilities for 2 power j) at this point if statement will true and run
f = f - (int)Math.Pow(2, j) that turn f to 4 then run
cbx3.Checked = true; in the later round of first loop when i=4 and j=2 , if statement will be true again and will run
f = f - (int)Math.Pow(2, j); that turn f to 0 then run
cbx2.Checked = true;
3.The myBinaryCheckboxes1 is unclear for me specially (f & 0x0001). What means that?
|
|
|
|
|
1. the logic in your code is flawed, it isn't just too complex as I wrote earlier, it also is wrong. The easiest way to make this obvious is this: f is used once, to initialize the for-loop on "i"; modifying f later on has no net result, as f isn't used any more. This cannot possibly be correct.
I added some log statements, writing intermediate values to the console, and it clearly shows f going negative and all output being wrong. Here is what I ran:
using System;
class test {
static void Main() {
cycle(8);
cycle(12);
Console.WriteLine("done");
}
public void cycle(int f){
Console.WriteLine("testing with f="+f);
int i, j;
if (f == 0) return;
for (i = f; i >= 0; i--) {
Console.WriteLine("i="+i);
for (j = 0; j <= 10; j++) {
if (i == Math.Pow(2, j)) {
f = f - (int)Math.Pow(2, j);
Console.WriteLine("found bit "+j+"; f now equals "+f);
break;
}
}
}
}
I suggest you either learn to work with a debugger (such as Visual Studio) using single-stepping, breakpoints, watch variables, and the like. Or add log statements as I did in the above code.
2. 0x0001 is a hexadecimal literal value, and & is the bitwise AND operator. Both should be explained in all their detail in any introductory book on C#. I strongly recommend you get such a book, if you don't yet have one, and start studying the language.
|
|
|
|
|
Nice.
I would just change to use an int as tag right away. So there would be no need to parse.
Ciao,
luker
|
|
|
|
|
Oh yes! what was I thinking?
[ADDED] wait a moment, how do I get an int there (except with more code)? when I type something into Visual Designer, isn't the tag always going to be a string? [/ADDED]
Luc Pattyn [My Articles] Nil Volentibus Arduum
modified on Tuesday, August 23, 2011 8:08 AM
|
|
|
|
|
No, an object -- so you need to cast. But can't you simply derive your own control and add exactly the field/property you need?
|
|
|
|
|
1.
I agree a Control's Tag property officially is of type object , however entering abcde (or 123) in Visual Designer's property pane for a Button resulted in a statement this.btnOK.Tag = "abcde"; (or "123") in the Xyz.Designer.cs file, so I woulds say VD creates strings, and one can cast the Tag to string, Parse it, or Convert it.
Simply casting to an int as in int aha=(int)btnOK.Tag; throws an InvalidCastException in both cases.
2.
Of course I could createa derived CheckBox, however I don't do that just to eliminate a single cast/Parse/Convert operation, there is too big an unbalance between amount of code added and elegance gained.
|
|
|
|
|
Luc Pattyn wrote: entering abcde (or 123) in Visual Designer's property pane
Obviously, I never do that. I do it the right way.
Luc Pattyn wrote: unbalance between amount of code added and elegance gained.
That depends on how many you need to create and how often they are accessed.
|
|
|
|
|
PIEBALDconsult wrote: I do it the right way.
So you are not using one of the Visual Designer Extensions for Notepad then?
|
|
|
|
|
Notepad is fine for XML, but unsuitable for code.
|
|
|
|
|