jugosoft 25 Junior Poster in Training

That maybe happens because page and master are not in the same folder. To solve this case register script file on page load.

jugosoft 25 Junior Poster in Training

- Make that procedure into Global.asax file.
- I think it's stupid that 2 same users are logged in the same time.

jugosoft 25 Junior Poster in Training

I don't think that is possible on server or client side. It can be done if you modify web browser.

jugosoft 25 Junior Poster in Training

I use them rarely, but some good books/tutorials could be found on Internet. I recommend you Microsoft Visual C# 2008 - John Sharp - Microsoft Press.

jugosoft 25 Junior Poster in Training

1. You could have a collumn which stores SessionID. When user logs in from another location, it replaces the SessionID and he is logged off from old location.
2. If I was doing that with timer in ASP.NET application, application would got crazy.
3. On each user action you can call function to check if user is logged.

jugosoft 25 Junior Poster in Training

Using delegates and events.

jugosoft 25 Junior Poster in Training

- Insert statement should be:

cmdSave.CommandText = "insert into tblMember(Std_ID,Last_N,First_N,Mid_N,Level,Section) values (@Std_ID,@Last_N,@First_N,@Mid_N,@Level,@Section)";

- You don't have to write explicity which data type is parameter (in some cases you must - very rare), and when you add parameter to SqlCommand there should be no '@' sign.

cmdSave.Parameters.Add(new SqlParameter("Std_ID", this.txtStud_ID.Text));
cmdSave.Parameters.Add(new SqlParameter("Last_N", this.txtLast_N.Text));
cmdSave.Parameters.Add(new SqlParameter("First_N", this.txtFirst_N.Text));
cmdSave.Parameters.Add(new SqlParameter("Mid_N", this.txtMid_N.Text));
cmdSave.Parameters.Add(new SqlParameter("Level", this.cmbLevel.Text;));
cmdSave.Parameters.Add(new SqlParameter("Section", this.txtSection.Text));

Advice

Use Trim() when inserting data into database.

jugosoft 25 Junior Poster in Training

If you use SQL Server Authentication (which is true this case) you must set Integrated Security parameter to false. This should work:

return new SqlConnection(@"Data Source=68.71.135.2,2121;Initial Catalog=DBTest;Integrated Security=False;User ID=myId;Password=mypass;");
jugosoft 25 Junior Poster in Training

Use DataGrid.

vedro-compota commented: ++++++++++++ +1
jugosoft 25 Junior Poster in Training

I'm creating multimedia player for some compatition, but I'm facing with problem with measuring audio output which is going to speaker/s. How can I measure it without some compicated code like CoreAudioApi which I found on CodeProject forum. I tried it to use but I'm getting some COM casting error.

jugosoft 25 Junior Poster in Training

Have you tried to debug application? Try solving with it. Watch for location where SelectedIndex property is restarted.

Do you have a method that removes all rows from DataGrid/DropDownList. In all that methods there must be a code that saves selected index in session.

I solved my problem with session setting in some methods, where I selected item from list and selected index was -1 (default) because of Page_Load event.

jugosoft 25 Junior Poster in Training

1. Generate a random number with Random class. There must be an option in StreamReader/TextReader to get block from the specific location.

2. If that text file is in the same folder where application is, use just file's name eg.

StreamReader reader = new StreamReader("file.txt");
jugosoft 25 Junior Poster in Training
jugosoft 25 Junior Poster in Training

1. All variables declared in class are by default private. If you want that they can be visible to any method, try putting keyword public before data type.

public int variable1;

2. If you have location map, I think that there must be X and Y cooridnate?

jugosoft 25 Junior Poster in Training

Sql Server keeps date in MM/dd/yyyy format. I also had a problem because in Serbia format is: dd.MM.yyyy hh:mm:ss. But following code solve it.

public DateTime convertToUkStandar(string date) 
{
    DateTime dateVariable = Convert.ToDateTime(date);

    return dateVariable.ToString("dd/MM/yyyy hh:mm:ss tt");
}
jugosoft 25 Junior Poster in Training

Do you use the value that we saved or you didn't changed SelectedIndex in code to Session["index"]. Can you post your code?

jugosoft 25 Junior Poster in Training

I created it today with CSS and javascript. Use two events - onmouseover, onmouseout. When event is triggered menu, there should be a javascript function that will show/hide submenu.

function show() {
    // To hide submenu change block to none
    document.getElementById("element").setAttribute("display", "block");
}
jugosoft 25 Junior Poster in Training

To download you can just use Response.Redirect() function.

Response.Redirect("~/file.extension");
jugosoft 25 Junior Poster in Training

Date that you want to insert in SQL Server database must be in format MM/dd/yyyy, and time must be in format hh:mm:ss. Don't forget to set data type of collumn in database to datetime.

string dateAndTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss");

...
command.ExecuteNonQuery();
jugosoft 25 Junior Poster in Training

In this case, button is problem.

protected void button1_Click(object sender, EventArgs e)
{
    ...

    // Saving SelectedIndex property
    Session["index"] = dropDownList1.SelectedIndex;

    ...
}
jugosoft 25 Junior Poster in Training

When form is submitted, SelectedIndex property is lost, you must save it with query string, session or something, and then you can use it without error.

Response.Redirect("page.aspx?index=" + dropDownList1.SelectedIndex);

or

// Saving the selected index value
Session["index"] = dropDownList1.SelectedIndex;

// Getting selected index value
string index = Session["index"].ToString();
jugosoft 25 Junior Poster in Training

You can limit textbox's maximum length by settings its attribute length/max length to 4 in the Properties panel.

jugosoft 25 Junior Poster in Training

I wanted to tell you that you must configure your server to send response to client using html not aspx file. I think that can be configured in ISAPI, not sure.

jugosoft 25 Junior Poster in Training

1. UserRow reference is not added to a project. If you created that class, add reference, or if that class is in .NET Framework Base Class Library add reference to it with 'using' directive.

2. After createing a new instance of any class in C# there must be () or [] or {}.

var a = new UsersRow();
jugosoft 25 Junior Poster in Training

I didn't understand you. Do you have a problem with passing data or you want to select and pass all data from datagrid?

jugosoft 25 Junior Poster in Training

- I think that converting from ASP page to HTML can be done only when application is runed from server.

- I suggest you to use some other element, try replacing 'iframe' with 'div', 'table' or other element that could be replace for 'iframe'.

jugosoft 25 Junior Poster in Training

If you want to pass all that data, that can be done by passing an array or passing all that variables.

If you decide to use an array, you must split your data with something. Here's the code:

using System.Text.RegularExpresions;

...

public string[] convertToArray(argument1, argument2, argument3, ...) 
{
    string temporaryElemenets = argument1 + ";" + argument2 + ";" + argument3 + ";" + ... ;
    
    // ; is character that will split data. Eg. We have string 'abc; cba'
    // function will return array with values {ABC, CBA}
    return Regex.Split(temporaryElemenets, ";");
}
jugosoft 25 Junior Poster in Training

Upper code is based on that graphics is drawn on bitmap and that is returned as image(result).

Example (Open new project and try following code to understand):

private void Form1_Load(object sender, EventArgs e)
        {
            // new Point(x, y) - coordinates of upper left point of the piece
            // new Size(x2, y2) - coordinate of bootom right point of the piece
            pictureBox1.Image = LoadImagePiece(@"imagePath", new Rectangle(new Point(0,0),new Size(100,100)));
        }

        public System.Drawing.Image LoadImagePiece(string imagePath, Rectangle desiredPortion)
        {
            using (Image img = Image.FromFile(imagePath))
            {
                Bitmap result = new Bitmap(desiredPortion.Width, desiredPortion.Height, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage((Image)result))
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.DrawImage(img, 0, 0, desiredPortion, GraphicsUnit.Pixel);
                }
                return result;
            }
        }

If you don't understand, tell me to send you a project.

jugosoft 25 Junior Poster in Training

Global variable is variable that is visible to all methods in class. In VB they can be visible to all classes.

http://en.wikipedia.org/wiki/Global_variable

vedro-compota commented: +++++++ +1
jugosoft 25 Junior Poster in Training
public void connect() 
{
    SqlConnection connection = new SqlConnection("connectionString");

    try {
         connection.Open();
    }
    catch {
         // Show error
    }
    finally {
         connection.Close();
    }
}

Don't forget to add

System.Data.SqlClient

reference to project.

jugosoft 25 Junior Poster in Training
private string convertDate(string dateToConvert) 
{
     DateTime date = Convert.ToDateTime(dateToConvert);

     return date.ToString("MM/dd/yyyy");
}
jugosoft 25 Junior Poster in Training

Try with this:

public System.Drawing.Image LoadImagePiece(string imagePath, Rectangle desiredPortion)
{
   using (Image img = Image.FromFile(path))
   {
       Bitmap result = new Bitmap(desiredPortion.Width, desiredPortion.Height, PixelFormat.Format24bppRgb);
       using (Graphics g = Graphics.FromImage((Image)result))
       {
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(img, 0, 0, desiredPortion, GraphicsUnit.Pixel);
       }
       return result;
   }
}
jugosoft 25 Junior Poster in Training

Your code in vulnerabile with SQL injection. Always use parametarised queries:

public void checkUsername() {
            string qry = "SELECT Password FROM Tablename WHERE User=@username";
            using (SqlConnection conn = new SqlConnection("YourConnectionString"))
            {
                try
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(qry, conn);
                    cmd.Parameters.Add(new SqlParameter("username", userName.Text));
                    SqlDataReader reader;

                    reader = cmd.ExecuteReader();
 
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            if (edtPassword.Text == reader["Passwrod"].ToString())
                            {
                                //what needs to happen if after this
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Username was not found", "Error",  MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Opening Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    conn.Close();
                }
 
            }
       }
jugosoft 25 Junior Poster in Training

Pass values with the class constructor:

Form that you want to open:

...

string arg;

public className(argumentThatYouWantToPass) {
    InitializeComponents;
    
    arg = argumentThatYouWantToPass;
}
...

Form that will open another form:

public void openForm() {
    Form2 form = new Form2(argument);
    
    form.Show();
}
jugosoft 25 Junior Poster in Training

Pass values by the class constructor:

Form that you want to open:

...

string arg;

public className(argumentThatYouWantToPass) {
    InitializeComponents;
    
    arg = argumentThatYouWantToPass;
}
...

Form that will open another form:

public void openForm() {
    Form2 form = new Form2(argument);
    
    form.Show();
}
jugosoft 25 Junior Poster in Training

I think he wanted to know how to create menu. Not DropDownList control.

Check following links for DropDownList menu:
- http://cssmenumaker.com/drop_down_css_menu.php
- http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=css+menu

kvprajapati commented: Thanks! +11
jugosoft 25 Junior Poster in Training

That code is for sending mail. You can have collumns for receivers of mail or you can have one collumn with data that are splited with eg. ';'. You also need a collumn that constains if mail was sent to A, B, C....

This is combination of simple reading data from database and mail sending.

To check if mail was sent to eg. 'A' > 'B' use 'if' statement.

jugosoft 25 Junior Poster in Training

Every time you update database with some data, send new e-mail:

try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtpServer");

                mail.From = new MailAddress("");
                mail.To.Add("");
                mail.Subject = "";
                mail.Body = "";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
// Redirect to error page
            }
jugosoft 25 Junior Poster in Training

You don't have to use ' character in T-SQL query except in data that you want to insert into table.

INSERT INTO table (column1, column2, column3, ...) VALUES('', '', '', ...)
jugosoft 25 Junior Poster in Training

I would use following query to check if there is a user with same username exists. Check can be performed with 'if' statement and reader.Read() function.

SELECT * FROM table WHERE username = @username

MitjaBonca is right.

jugosoft 25 Junior Poster in Training

You use default creditians, and you specified to use your creditians. That could be why the error is generated. Change following section of your code to:

protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
 
            MailMessage mm = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            mm.From = new MailAddress(txtFrom.Text);
            mm.To.Add(new MailAddress(txtTo.Text));
            //mm.To.Add(new MailAddress(umamahesh2020@gmail.com));
            mm.Subject = txtSubject.Text;
            mm.Body = txtMessage.Text;
            mm.IsBodyHtml = true;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "xxxx@gmail.com";
            NetworkCred.Password = "xxxx";
            smtp.UseDefaultCredentials = false; // I changed this value to false
            smtp.Credentials = NetworkCred;
            smtp.Port = 587;//this is Gmail port for e-mail
            smtp.Send(mm);//send an e-mail 
 
            MessageBox.Show("Message Sended");
        }
        catch 
        {
 
        }
    }
jugosoft 25 Junior Poster in Training

Thanks. Your code works with some changes in DrawEan13Barcode method.

jugosoft 25 Junior Poster in Training

I'm creating some barcode generator, and I want to save generated barcode to database, but I have a problem when I want to get bytes from PictureBox Image. It says that Image property is null. That's hapening because barcode is drawn on the PictureBox(not in Image property). I think that I could solve it by converting graphic to bitmap, but I don't know how?. Here's the code:

Graphics graphics = barcodePictureBox.CreateGraphics();

            graphics.FillRectangle(new SolidBrush(SystemColors.Control),
                new Rectangle(0, 0, barcodePictureBox.Width, barcodePictureBox.Height));

            EAN13 = new Ean13();
            EAN13.CountryCode = "680"; // Yugoslavia
            EAN13.ManufacturerCode = "69048";
            EAN13.ProductCode = RandomNumberGenerator.Generate();
            if (ceksuma.Length > 0)
                EAN13.ChecksumDigit = checksum;

            EAN13.Scale = (float)Convert.ToDecimal("1.0");
            EAN13.DrawEan13Barcode(graphics, new Point(0, 0));
            checksum = EAN13.ChecksumDigit;
            graphics.Dispose();
jugosoft 25 Junior Poster in Training

You can set ListBox's property 'Sorted' to 'true'. If you are using an array, make sure that sorting doesn't change combination of members. If you are using an array, there is a sort function.

jugosoft 25 Junior Poster in Training

You need to specify the download location. That means instead:
"C:\\Users\\Skull\\Desktop" you need to put "C:\\Users\\Skull\\Desktop\\Lsusb.tar.bz2".

Here's the documentation:
http://msdn.microsoft.com/en-us/library/ez801hhe(v=VS.100).aspx

jugosoft 25 Junior Poster in Training

You can use 'AJAX Control Toolkit'. There is a SlideShow control. But if you want to use Javascript(which is the harder way) you could search Google. I suggest you to use AJAX Toolkit.

jugosoft 25 Junior Poster in Training

You can, like you pass values to for example SqlConnection constructor.

vedro-compota commented: ++++ +1
jugosoft 25 Junior Poster in Training

You can use the following code. Code if for MS SQL Server, but if use for example Access database change "SqlConnection" to "OleDbConnection" or "OdbcConnection".

Private Function count() As Long
   SqlConnection connection = New SqlConnection("connectionString")
   SqlCommand command = New SqlCommand("SELECT COUNT(*) FROM tableName WHERE condition = ''",connection)
   SqlDataReader reader

   Long result = 0

   Try
      connection.Open()
      reader = command.ExecuteReader(CommandBehaviour.Default)

      If (reader .Read()) Then
         result = reader.GetValue(0)
      Else
         result = 0
      End If

      connection.Close()
   Catch ex As Exception
      ' ERROR
   End Try

   Return result;
End Function
kvprajapati commented: Solved! Close both, reader & connection +11
jugosoft 25 Junior Poster in Training

Try with this code, I changed SQL query and parameter:

string connectionString = null;
            OleDbConnection connection;
            OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
            string sql = null;
            connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=Book.mdb";
            connection = new OleDbConnection(connectionString);
            sql = "delete from Books where BookKey = @BookKey";
            try
            {
                connection.Open();
                oledbAdapter.DeleteCommand = connection.CreateCommand();
                oledbAdapter.DeleteCommand.CommandText = sql;
                oledbAdapter.DeleteCommand.Parameters.Add(new OleDbParameter("BookKey", OleDbType.Char, 0, "BookKey"));

                MessageBox.Show("row deleted");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                connection.Close();
            }
jugosoft 25 Junior Poster in Training

I never use ToolTips that are definder in control properties. I always make a my tooltip, here's the code:

Private toolTipInformation As New ToolTip

Private Sub show()
    toolTipInformation.Show("some text", window)
End Sub

Private Sub hide()
    toolTipInformation.Hide(window)
End Sub

window
Type: System.Windows.Forms.IWin32Window
The Control to display the ToolTip for.