JerryShaw 46 Posting Pro in Training

Sorry, Didn't mean to say it should go away, I know that it is important to have them to help fund this great web site.
What I would like, is that Ask.com not popup and transfer focus to that new window when I am trying to write a message in the DaniWeb site. It is not a problem with the advertisement, but how your web guy handles the Enter key in the private message editor section.

Thanks,
Jerry

JerryShaw 46 Posting Pro in Training

Load the image into a byte array.
Pass the byte array into a memory stream
Pass the memory stream into a new or existing bitmap.

byte[] b = (byte[])adm["Image_image"];
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
                        stream.Write(b, 0, b.Length);

Bitmap bmp = new Bitmap(stream);

Error checking, null checking, etc needs to be added, left out for simplicity

Jerry

JerryShaw 46 Posting Pro in Training

Please get rid of that darn Ask.com advertisement when writing private messages. When trying to write a message, the Enter key causes the Ask.com search page to launch.

Makes it very frustrating to write a message.

Jerry

JerryShaw 46 Posting Pro in Training

Sounds like the program is busted... or has a dependency. If the program needs a dll, or some other object from its local directory (where it is running) it will break if the file it needs is missing.
If the program can be launched in its debug directory (without VS running) then I believe that is your problem.
Copy the additional files to your other computer or hard-drive, and it should be okay.

JerryShaw 46 Posting Pro in Training

You can save any size file, or image or anything else that you want into an SQL database.
This capability has been around even back when SQL was SyBase.
The Text field is a BLOB field. Use a byte[] array, and stream the file into the field through a memorystream or filestream. When you want to get it back our, again, use a byte array to stream it out. Check out how to store and retireve images, and you use the same method for files.

There are lots of document companies that store zip files, PDF, and Word Doc files (and other types) directly into SQL databases. Storing to the hard drive is not a good option because it opens a security hole if the customer has to have a network share to retireve the file.

Jerry

JerryShaw 46 Posting Pro in Training

Do you know exactly which ones you want to write to Text ?
Do you want to use their Names ? (example checkbox1, checkbox23)
Instead of names, do you want to use a Tag value to determine which ones are to be written to Text ? (example all checkboxes with a Tag = "Save this checkbox to text"; ?

You have some checkbox components you want to write to Text... I assume that you already know which ones you want to use. So you now just need to identify which ones you want written.

Let me know how you want to proceed. If you want, you can send your project to me (zipped) at shawjh@meadowcrk.com and a list of the checkboxes you want saved, and I can show you how in your own code.

Regards,
Jerry

JerryShaw 46 Posting Pro in Training

Great Minds think alike :)
I too have the same exact method in my Global static class. Although I have a "finally" in mine to handle closing the connection just in case of an error. I instantiate the connection from a Global connection string. I have inlcuded my Stored Procedure handling method for your ammusement.

By using the "params" statement, I can pass any number of SqlParameters that a proc will need. Our company (DBA) insists on no embedded SQL in our projects, But I have both methods anyway, and use my Global class in multiple apps.

public static void ExecuteNonQueryStoredProcedure(string ProcedureName, params SqlParameter[] values)
        {
            SqlConnection conn = new SqlConnection(Global.ConnectionString);
            try
            {
                SqlCommand cmd = new SqlCommand(ProcedureName, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                if (values != null && values.Length > 0)
                    cmd.Parameters.AddRange(values);
                conn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                MessageBox.Show("Update failure in Global.ExecuteNonQueryStoredProcedure\r\n" + e.Message);
                throw e;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
JerryShaw 46 Posting Pro in Training

I prefer using the SqlCommand as well. One approach is to create a method (even perhaps a static method) that you can pass a T-SQL statement, and it does all the work, or you can pass a stored procedure name and a array of parameters for the proc to use. Comes in real handy.

JerryShaw 46 Posting Pro in Training

use a NotifyIcon component. Use the FormClose event handler of your form to cancel the close. However you need to provide some method of allowing them to close the app.
See NotifyIcon on google or MSDN for a number of examples.

JerryShaw 46 Posting Pro in Training

You can place just about anything on the toolstrip.
First (in the IDE) place the desired component on the form (anywhere will do).
Provide yourself with a ToolStripControlHost type variable.
Then when the form in instantiated, do this:

private ToolStripControlHost dtTScomponent;

public form1()
{
            InitializeComponent();
            dtTScomponent = new ToolStripControlHost(dtMyDateTimePicker);
            MainToolStrip.Items.Add(dtTScomponent); 
}

dtMyDateTimePicker is the component you dropped on the form, and eventually want to live on the tool strip. The hosting variable is instantiated and takes dtMyDateTimePicker as its child. When the new host is added to the toolstrip, the datetime picker goes with it.
You can set the properties of the toolstrip collection and the dtTScomponent properties to get the desired appearance. From that point on, you do not need to refer to the dtTScomponent for anything... it is just a host.

JerryShaw 46 Posting Pro in Training

Can you define the problem you are having ?
Are you referring to a Toolstrip or something else ?

JerryShaw 46 Posting Pro in Training

If you are trying to launch the application from a different machine across the network, then yes you will get this error until you make it a trusted application. There are a number of security setting that have to be made, and there is a couple free utilities on the internet that allow you to modify the settings to allow it to work this way.

JerryShaw 46 Posting Pro in Training

Yes this board seems to attract students wanting someone else to do their homework.
Think about it, If you give them all the answers, and they end up with a degree in computer science, then get a job at your business, and end up on your team...you can only blame youself for doing all their homework. They will be worthless to a programming team unless they actually put in the time, and learn this stuff.

Please stop posting homework assignments. Ask questions on the why, and how, but don't expect us to do your homework for you.

JerryShaw 46 Posting Pro in Training

First, your ASP is the one connecting to the database using the credendials of the web site setup. (Windows authentication mode).

You are to validating the information from the login screen against the database. Just keep in mind that SQL sees the web service as the one logged in not the credentials or person supplied in the query. IOW, the user is not logged in as the user. You connection string is using windows authentication, meaning it takes the web service credentials as the logged in user.

Does that help ?

JerryShaw 46 Posting Pro in Training

What Ramy said plus specifically look at FileInfo to get the file name, use the name property with the string.split function to break it up. If you are scanning an entire directory then consider looking at the DirectoryInfo's getfiles to get an array of fileinfo.

JerryShaw 46 Posting Pro in Training

Yes to both questions.

Bind the Combobox to the table or a bindingsource, and set the DisplayMember to what you want shown in the Text property and the ValueMember to the key data.

Now if you want to do this as an unbound control, then you will need to use some code.
IOW, if you do not want the combobox items to be populated by the database, but rather just use the items list you provided in the IDE it takes a bit more work. There are several approaches to consider. First the ugly way, means creating a method that will interpret the selected item index or Text value and return the desired value. Another method is to set the item index based on the data column value. Some programmers create an array or generic collection to supply the means of interpretation (value to text / text to value).

A slightly more elegant method is to create a class that allows you to emulate the operation of a bound control. Since the combobox item is of type Object you can stick just about anything you want in there, however it must supply as a minimum a ToString() method that will return the information to display as Text.

public class itemobject
    {
        private string Text;
        private int value;
        public itemobject(string Text, int value)
        {
            this.Text = Text;
            this.value = value;
        }
        public override string ToString()
        {
            return Text;
        }
        public int Value { get { return …
JerryShaw 46 Posting Pro in Training

Make sure you understand the difference between "modal" and "non-modal" forms.
When you use ShowDialog() this causes the form to be loaded as a modal form. A modal form retains focus (for the application) until it is closed. The form that calls this modal form is suspended until the modal form is closed.

The use of the Show() method will cause the form to be loaded as a non-modal form, and not suspend the caller form. This allows both forms to be active, and accept user input on either form.

Typically you will use the ShowDialog method when you want to display some information or gather user input that is required before the user can continue some main task. The sub-form is closed, and the main application continues.

You can use the Hide() method on non-modal forms (The main form is defaulted to non-modal). This will simply hide the form from the desktop. Calling Show() again will bring it back.

All that being said, you should be able to show and hide forms at will. You should consider the implications of using multiple non-modal forms. In many cases, information is shared between forms, or atleast between the main form and the sub-form. If this is the case, you can create the sub-form variable outside of a method, and allow the main form and the other sub-forms to use this variable to pass information, call its methods, etc. If you do this, you will want to …

JerryShaw 46 Posting Pro in Training

What Ramy is saying is that you do not specify a File name, but rather a ConnectionString.

SqlConnection conn = new SqlConnection("Data Source=Servername;Initial Catalog=Marketing;Integrated Security=SSPI");
conn.Open();
JerryShaw 46 Posting Pro in Training
string constr = string.Format( "Data Source={0};Initial Catalog={1};Integrated Security=SSPI", YourServerName,YourDatabaseName);
JerryShaw 46 Posting Pro in Training

You are not by chance trying to run the application from a network share or mapped drive ?

JerryShaw 46 Posting Pro in Training

I have attached a Visual Studio 2005 project (as a zip file) that shows how to save your values from the form to a text file, and as an added bonus, a way of bringing those values back from a text file.

It uses a couple recursive methods .
There are certainly ways to streamline it. You could even use reflection to help save every property and event declaration to an XML file, and regenerate the form to a specific state on demand.

If you want to get real creative, you could actually Create a new blank form and populate it from the XML file (except for the events.). This demo project does nothing like that.

All the demo project does is write a simple text file with the Component Name=value combo.

Have Fun,
Jerry

JerryShaw 46 Posting Pro in Training

Check the project properties to see where it is placing the end result. If it is showing success, it means it wrote something somewhere.

JerryShaw 46 Posting Pro in Training

The code looks basicaly correct, however a couple things to point out.
1) You should avoid creating procs that start with "sp_" because this tells SQL to first look in the system procedures.

2) In your proc, you may consider also testing to see if that username already exists, and raise an error if not. Also check that the current password is correct.

3) You must open the connection before executing the sproc.

4) Use the schema as part of the sproc name to avoid confusion when working with multiple schemas.

5) Consider encrypting the passwords so when (not if) someone gets access to that table they don't get all of your users and passwords.

if exists(select * from login where username=@username)
begin
... do you update stuff
end
else
raiserror('Invalid User',16,-1)

you can shorten your code a wee bit by using this:

SqlConnection conn = new SqlConnection(@"Data Source=R2\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True");

SqlCommand chpass = new SqlCommand("dbo.sp_ChangePassword",conn);

chpass.CommandType = CommandType.StoredProcedure;

chpass.Parameters.AddWithValue("@UserName",Piname.Text);
chpass.Parameters.AddWithValue("@Password",currpass.Text);
chpass.Parameters.AddWithValue("@NewPassword",newpass.Text);


try
{
conn.Open();
chpass.ExecuteNonQuery();
errLabel.Text = "Password Sucessfully Changed";
}catch(Exception exp){errLabel.Text=exp.message;}
finally{ conn.Close(); }

--Jerry

JerryShaw 46 Posting Pro in Training

Your problem is in the NINI code.

I have attached my TiniFile class library with source for you to use in place of the NINI library. It has just about anything you would ever need to work with an ini file. If you find something it doesn't do, drop me a line and I can add it in a flash.

Jerry

JerryShaw 46 Posting Pro in Training

Yes, I used Visual Studio 2005 to create the project.

It is basically what someone else posted later on:

int Fridays = 0;
            int m_Month = cbMonth.SelectedIndex + 1;
            int m_Year = Convert.ToInt32(edYear.Value);
            DateTime dt = new DateTime(m_Year, m_Month, 1);
            while (dt.Month == m_Month)
            {
                if (dt.DayOfWeek == DayOfWeek.Friday)
                    Fridays++;
                dt = dt.AddDays(1);
            }
            edFridays.Text = Fridays.ToString();

A combobox with all the months (cbMonth), and numericupdown (edYear) and a a simple textbox (edFridays), and ofcourse a Go button that calls the code above.
Basically you need to use the DateTime property (DayOfWeeK0 to determine its day, and increment a counter.

Jerry

JerryShaw 46 Posting Pro in Training

I have attached a project that demonstrates how to do this.

Jerry

JerryShaw 46 Posting Pro in Training

Writing an ini parcer is pretty straight forward.
I have attached a class library that I use, and included the source code for you to check out.

JerryShaw 46 Posting Pro in Training

Using a Stored Procedure with a Data Adapter
In this example, I have a database named SoftwareInventory with a table named Software and a Stored procedure named proc_GetCadyData that takes one parameter named @CadyName (nvarchar(50))

Establish an SQL Connection
Then create an SQLCommand. Set it to use the CommandType of StoredProcedure.
Add the @CadyName parameter
Create the DataAdapter, and use this new SQLCommand as its parameter.
Fill the dataset from the adapter.

That's all there is to it...

Jerry

private void LoadData()
        {
            SqlConnection conn = new SqlConnection("Data Source='SHAWHP\\SQLEXPRESS';Initial Catalog=SoftwareInventory;Integrated Security=SSPI");
            SqlCommand cmd = new SqlCommand("dbo.proc_GetCadyData", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@CadyName", "Cady-A");
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            
            dataSet1.Tables.Clear();
            adapter.Fill(dataSet1, "Table");
            MyGrid.DataSource = dataSet1.Tables["Table"];
            bindingSource1 = new BindingSource(dataSet1, "Table");
            bindingNavigator1.BindingSource = bindingSource1;
            MyGrid.DataSource = bindingSource1;
        }
JerryShaw 46 Posting Pro in Training

SQL has the ability to store any type of data into a blob field. Just stream the data into the column. There are many examples on Code Project, and other sites on how to do this.

JerryShaw 46 Posting Pro in Training

You should explain your issue in more detail.
Getting data from a table is simple.
Getting text from a textbox is simple.

It is not very clear on what you want to do with the data or the text. What kind of database ?
Are you going to use data binding, or direct assignment ?

-- Jerry

JerryShaw 46 Posting Pro in Training

select [Arabic_Term], [English_Term] from [databse].[dbo].[mytable] where [ID]=123

JerryShaw 46 Posting Pro in Training

Jugortha has given you the way to get the the current cell into a text box. Have you looked at just binding the Textbox (and other) components to the same BindingSource as the DataGridView... then let the great binding capabiliites handle populating all the controls for you.

JerryShaw 46 Posting Pro in Training

Make frmLogin.UserAccount public.

JerryShaw 46 Posting Pro in Training

Ravenous Wolf,

Can you provide a sample of the code (your repeated 16 lines segments ). Yes you can create control arrays. If you find yourself typing the same 16 or so lines for multiple controls, it begs for a method to perform that action. Give us some code that shows what you are trying to do, and I will try to show you a better way.

--Jerry

JerryShaw 46 Posting Pro in Training

ConfusedMuchMor,
as scru mentioned a field aka property, variable or parameter that holds a value or collection of values. You can assign values to and get values from these types of objects.

A method on the otherhand is a piece of executable code. It may return nothing (void) or return a value. Typically you will use a method to cause something to happen such as populate some component on your form, or carry out any number of tasks.

To understand some of these basics, you should grab one of the many wonderful programming books. All programming languages have the basic concepts of storing data in some variable, and calling methods (also called functions and procedures in different languages).

//Jerry

JerryShaw 46 Posting Pro in Training

I assume you have already figured this out on your own ?

JerryShaw 46 Posting Pro in Training

If you are referring to placing another form into a Panel on the Main form, this should really be done using a UserControl. However,

Form2 fm2 = new Form2();
            fm2.TopLevel = false;
            fm2.Dock = DockStyle.Fill;
            panel1.Controls.Add(fm2);
            fm2.Show();

You can put a form into another control (such as a panel) on a TopLevel form like your main form by using the code above. You should typically set the second form's control box off, and set the Text of the second form to empty, also set the border to none.. But that is just you choice.

//Jerry

JerryShaw 46 Posting Pro in Training

raghu,

That SQL statement should have thrown some errors.
I assume you are using Microsoft SQL.
First off, it is typically not a good idea to use commandtext. Instead use stored procedures whenever possible.
Although you are adding parameters to the CMD, because the CMD type is CommandText those parameters
are not going anywhere. Also, you need to format the CommentText properly. Example:

cmd.CommandText = "Update login1001 Set name = @username1001, pwd = @userpassword1001 where username1001= @username1001";
cmd.CommandType = CommandType.Text;

should be rewritten as such:

string m_username = "Whatever this user name is";
string m_pswd = "whatever the password is";
SqlConnection con ... all that jaz...
cmd.CommandText = string.Format("update login1001 set [name]='{0}', pwd='{1}' where username1001='{0}' ",  m_username, m_pswd);
con.open();
try
{
   cmd.ExecuteNonQuery();
   Label2.Text = "updated successfully";
}
catch (Exception eSql)
{
  Label2.Text = "Failed to Update: Error:"+eSql.Message;
}

I prefer to use stored procedures, and the rest of this response is geared towards
that end.

If you want to check to see if these credentials are okay then rewrite your sp_UserValidation like this: (BTW, Never use sp_ as the start of a stored procedure name, because this tells the SQL Plan to first look at the system procs first... waste of time and resources)

create procedure proc_ValidateUser @UserName varchar(50), @UserPassword varchar(20)
AS
   if not exists (select top 1 username from Login1 where username=@UserName and 
     userpassword=@UserPassword)
     raiserror('Invalid User',16,1)
GO

Or you could write it to return a scalar value of 1 …

JerryShaw 46 Posting Pro in Training

I didn't find this error when I compiled it.
I optimized it a bit, and set the voice default (which you did not.. which might have something to do with it.

Anyway, I have attached my version of your project for your review.

Jerry

JerryShaw 46 Posting Pro in Training

I think you are struggling with understanding the one to many relationship.
Lets say you have 2 countrys defined in your country_master table. #1=USA, #2=Canada

You can have all USA's states listed in the states table, and you can also have all of the states found in Canada in this very same table. Each row in the states table also has a Country ID column that allows the SQL server to only get the states for a specific Country ID.

Therefore a T-SQL statement of "select * from States where Country_id=1"
will only bring back the states that belong to the USA. If Country_ID were set to 2 in this query, then only Canada's states would be returned.

The purpose of the first drop-down is to get the CountryID that will be used in the query against the States table... As long as you issue the query statement with the "where country_id = nnn", the second dropdown will only contain the states related to that country id.

Hope this Helps,
Jerry

JerryShaw 46 Posting Pro in Training

You need two database tables.
One to store the Country ID and Name
The second table to store the Country ID, State Name and State Capital. Simple one to many relationship. Each country has many states, but a state only has one capital.

Populate the first combo with the country, and the value member with the country id. The second combo will contain the state name, and you can place the capital in the value member. If you web site is doing more with the state information then you might want to place a state id in the states table, and use that as the valuemember so that you can pull additional information about the state.

In the demo, you will see the event on the second drop down selected index change uses the country id, and the state id to find the capital value to place into the Label.

--Jerry

JerryShaw 46 Posting Pro in Training

Attached is a simple ASP.net project that demonstrates the double drop-down.
Now this is not real efficient. If this were to be used for a production site, you should cache the information, and use JavaScript or AJAX methods to display the information rather than return to the server side.

Jerry

JerryShaw 46 Posting Pro in Training

rahgu,

What version of c# are you using ?
There are some differences that can cause these problems.

I know you are in dire need of this, but I have to go to work in a few minutes. If you are willing to wait until tonight (California time) I will write it as an ASP application to get rid of the problems you are seeing.

In the mean time, you can modify the code I sent to be used as a Windows Application so you can see how it works. Works flawlessly here.
That may help you get it working in ASP.

I will post the APS version in about 10 hours.

--Jerry

JerryShaw 46 Posting Pro in Training

Attached is a Windows Application project that demos what you are looking for,
I am using my own server (connection string), and it uses two tables. Read the top of the form.c to see my comments.
You should have no problem converting this to asp.

Good luck,
J

JerryShaw 46 Posting Pro in Training

ok, I will write the code example, and post it here in the next few minutes.

JerryShaw 46 Posting Pro in Training

Your code should work fine as is, you just need to give the Where Country_id= ... in the query so that it returns the states for that country.

protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
{
string countryid;
countryid = dd1.SelectedValue;
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlDataAdapter da1 = new SqlDataAdapter(string.Format("SELECT stateid,statename FROM countrystate where country_id='{0}' ",countryid) );
DataSet ds1 = new DataSet();
da1.Fill(ds1, "countrystate");
dd2.DataSource = ds1.Tables["countrystate"];
dd2.DataTextField = "statename";
dd2.DataValueField = "stateid";
dd2.DataBind();
}
JerryShaw 46 Posting Pro in Training

You need to specify what country to use when you pull the data for the second drop down.

string sql = "SELECT stateid,statename FROM countrystate where country_id='{0}' ";
SqlDataAdapter da1 = new SqlDataAdapter( string.Format(sql,countryid) );

This way it will only contain the states for that country.

JerryShaw 46 Posting Pro in Training

Okay, this web server is connecting to an SQL Server. Is the SQL Server on the same machine as the WebServer ?
If so, is the SQL Server part of the same domain as the WebServer ? And is that Domain named "STS-SYNMAC" ? and do you have the SQL Server setup to authenticate users of that domain ?, and is the "userName" Windows account valid in that domain ?
Use SQL Studio to explicity allow this Domain\Account, and give it rights to the OReports catalog.

This is purely an authentication problem on that server. Can you launch a Windows App on that server, and see if it can connect to the SQL server ?

JerryShaw 46 Posting Pro in Training

Simply write an event handler on the SelectedIndex change of the combobox to adjust the item for the second. On the second, have another event handler that sets the textbox value. You can populate a Combo using objects that contain the matching information to go into the text box.
Is this a homework assignment ?

JerryShaw 46 Posting Pro in Training

This error occurs simply because you do not have a user established on that SQL server with that name. If the user is Windows Authenticated, then it will use the logged in user name and domain [domain]\[logged in user name]. If "STS-SYNMAC\userName" is not a valid user in that domain, and that domain is allowed on that SQL server, then you will get the error.

If using SQL Authentication, then you will have to first make sure the SQL server allows that option, and make sure you have a user with that name.