Ramesh S 129 Posting Pro

Hi,

Declare the Connection object myConn before the try clause and initialize it within the try.

I suggest to change your code as follows:

protected void Names()
    {

        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\\project\\Db.mdb");
        OleDbDataReader myReader = null;
        string strQuery = "SELECT TOP 1 Name FROM Names";
        try
        {

            myConn.Open();
            OleDbCommand myComm = new OleDbCommand(strQuery, myConn);
            myReader = myComm.ExecuteReader();
            if (myReader.HasRows)
            {
                myReader.Read();
                Session.Add("Name", myReader[0].ToString());
                myReader.Close();

                //reuse the myConn connection
                strQuery = "SELECT bla bla bla WHERE bla bla bla";
                OleDbCommand myComm2 = new OleDbCommand(strQuery, myConn);
                myReader = myComm2.ExecuteReader();
            }
        }
        catch (Exception er)
        {
            Response.Write("Error:" + er.Message);
        }
        finally
        {
            if (myReader != null)
            {

                myReader.Dispose();
            }

            if (myConn != null)
            {
                myConn.Close();
                myConn.Dispose();
            }
        }
    }
Ramesh S 129 Posting Pro

Hi,

Glad to hear that you found a solution. Please mark this thread as solved.

Ramesh S 129 Posting Pro

Hi,

To analyze the problem, It would be better if you post the method/complete code snippet where this error occurs. Because this error could be occurred due to issue in the other lines of code. Please provide the VS and asp.net project version details.

Also refer following links.
http://msdn.microsoft.com/en-us/library/8dy0ah20%28v=vs.80%29.aspx
http://stackoverflow.com/questions/3764476/vb-net-linq-to-datatable-error-end-of-statement-expected
http://www.dreamincode.net/forums/topic/195427-end-of-statement-error/

Ramesh S 129 Posting Pro

Hi,

The machine.config file can be located in the following folder in the server/PC.
drive:\<windows>\Microsoft.NET\Framework\<version>\config\machine.config

You can open it using notepad or VS 2005.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/management/mgmtapi.aspx

Ramesh S 129 Posting Pro

Hi,

Just check the control's ID found in the JavaScript and ID tag of the image control in the HTML source. You can do it by Right click->View Source.

Ramesh S 129 Posting Pro

Hi nick3592,

In addition to Lusipu advise, Here is mine,

To develop web applications in asp.net, you need to learn any of the programming languages C# or VB.NET and .NET object model (classes/components) specific to asp.net.

If you learn C# or VB.NET, you can also easily work in the following .NET based application platforms with little learning curve.

1. Desktop Applications (Windows Forms)
2. SharePoint Development
3. Microsoft Dynamics CRM
4. Microsoft BI platform
5. Windows Mobile Development

Also you can work BizTalk Server and Axapta Dynamics development etc . Becuase .NET Framework is the base for all Microsoft based platform customization. All you need to do is you have to learn the platform specific object model to work in that.

Ramesh S 129 Posting Pro

Hi,

Mark this thread as solved if your question is answered.

Ramesh S 129 Posting Pro

Hi,

Refer the following link.

ASP.NET Hosting Tutorials

Ramesh S 129 Posting Pro

Hi,

You need to bind the GridView, after inserting records into the database. Here is the sample code.

Imports System.Data
Imports System.Data.OleDb
Partial Class DemoPage1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindGridView()
        End If
    End Sub

    Private Sub BindGridView()
        ' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
        Dim dt As DataTable = New DataTable()
        Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
        conn.Open()
        da.Fill(dt)
        da.Dispose()
        conn.Close()

        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Code to add new record to SQL Server table
        Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")

        Dim sqlinsert As String

        sqlinsert = "INSERT INTO sysdep (sysaccount,syspw)" & _
          "VALUES(@sysaccount, @syspw)"

        Dim cmd As New OleDbCommand(sqlinsert, con1)

        cmd.Parameters.Add(New OleDbParameter("@sysaccount", TextBox1.Text))
        cmd.Parameters.Add(New OleDbParameter("@syspw", TextBox2.Text))

        Try
            con1.Open()
            cmd.ExecuteNonQuery()
        Catch ex As OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
        End Try
        con1.Close()

        BindGridView()
    End Sub
End Class
Ramesh S 129 Posting Pro
Ramesh S 129 Posting Pro

Hi,

You can reset Visual Studio Settings in two ways
1. From Visual Studio IDE
Click Tools Menu->Import and Export Settings->Reset all settings.

2. From Command Prompt
Start Menu->All Programs->Microsoft Visual Studio 2008->Visual Studion Tools-> Visual Studio 2008 Command Prompt. This will open the command prompt. Type the following command: devenv.exe /resetsettings

Ramesh S 129 Posting Pro

Hi,

ASP.NET 3.5 social Networking by Andrew Siemer is a good book which you guide to building enterprise-ready social networking and community applications with ASP.NET 3.5.

DotNetNuke is the leading open source web content management system (CMS) and application development framework for Microsoft .NET. You can try to implement the Social Networking modules. Smart-Thinker is a free DotNetNuke Social Networking Solution and the DotNetNuke Toolbar.

Also look into this article: Nine Ways to Build Your Own Social Network

Ramesh S 129 Posting Pro

thanx alot sir..
really its work..:)

Hi,

Please mark this thread as solved if you feel that your question has been answered.

Ramesh S 129 Posting Pro

Put the return statement out of else block in GetCounterValue() method.

private int GetCounterValue()
    {
        StreamReader ctrFile;
        FileStream ctrFileW;
        StreamWriter sw;

        string Path = Server.MapPath("Counter.txt");
        string CounterContents;
        int nCounter;
        if (File.Exists(Path))
        {
            ctrFile = File.OpenText(Path);
            CounterContents = ctrFile.ReadLine().ToString();
            ctrFile.Close();
            nCounter = Convert.ToInt32(CounterContents);
        }
        else
        {
            nCounter = 0;
            nCounter++;
            ctrFileW = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write);
            sw = new StreamWriter(ctrFileW);
            sw.WriteLine(Convert.ToString(nCounter));
            sw.Close();
            ctrFileW.Close();
        }
   return nCounter;
    }
Ramesh S 129 Posting Pro

Instead of using Response.Redirect("Some file Name") using Response.WriteFile() method which writes the contents of the specified file directly to an HTTP response output stream as a file block. For example,

Response.WriteFile(@"D:\Temp\Test1.docx") ;
 //Response.WriteFile(path + fileToOpen);
Ramesh S 129 Posting Pro

Hi,

Check this link.

Creating Cascading DropDownLists in ASP.Net

It has sample code with table design and asp.net code. It exactly matches with your requirement.

Ramesh S 129 Posting Pro

In line 18, you are using SqlCommand object to open a connection which is wrong. You need to use SqlConnection object to open a databas connection.

SqlCommand represents a Transact-SQL statement or stored procedure to execute against a SQL Server database.

Try the following code.

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim connStr As String = "Data Source=RAHUL-034890AF0\SERVER2005;Initial Catalog=user_accounts;Integrated Security=True"
        Dim conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(connStr)
        Dim command As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand()
        command.Connection = conn
        conn.Open()
        command.CommandText = "YourProcName"
        command.CommandType = CommandType.StoredProcedure
        command.Parameters.Add(New SqlParameter("@Use_Name", System.Data.SqlDbType.VarChar, 20)).Value = txtUserName.Text
        command.Parameters.Add(New SqlParameter("@Password", System.Data.SqlDbType.VarChar, 6)).Value = txtPasswod.Text

        Dim reader As Data.SqlClient.SqlDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
        Dim result As Boolean = reader.HasRows
        reader.Close()
        conn.Close()
        If result Then
            Response.Redirect("~/salesbill.aspx")
        Else
            lblError.Text = "Username and password do not match"
        End If
Ramesh S 129 Posting Pro

Set the customErrors mode to 'off' in the web.config as specified in error message that you posted. It will adisplay actual error occured. Also check if any error message is posted in the Event Viewer.

Ramesh S 129 Posting Pro

Decided to do it like this:

if (Request.QueryString["ID"] != null)
            {
                command.Parameters.AddWithValue("@supplier_id", Convert.ToInt32(Request.QueryString["ID"]));
            }
            else
            {
                command.Parameters.AddWithValue("@supplier_id", 2);
            }

If theres a better way let me know!

Grant

Hi Grant,

The above approach seems to be okay. But still you can reduce the number of lines in the following way.

int supplierId = (Request.QueryString["ID"] != null) ? Convert.ToInt32(Request.QueryString["ID"]) : 2;        
command.Parameters.AddWithValue("@supplier_id", Convert.ToInt32(supplierId);
Ramesh S 129 Posting Pro

1. Tools->Internet Options->Security->Internet(zone)->Custom Level-> Under ActiveX controls and plug-ins, Enable the options.
2. It would be better to add your site to the Trsuted sites list and configure activex for that zone.

Ramesh S 129 Posting Pro

Hi Grant,
Request.QueryString["ID"] is read only collection which means that you cannot set/insert a value to the collection. But you can retrieve the value from the collection if exists. Request.QueryString is internally populated by ASP.NET when you pass query strings explicitly from a page.

Ramesh S 129 Posting Pro
Ramesh S 129 Posting Pro

Regular expression are used to validate inputs such as email, phone numbers etc. Basically they are used to validate if the input is in a pre-defined format.

In your case, the login control's input are validated against the user id and password which are stored in the backend database. Why do you need to use regular expression validators for this scenario?

Ramesh S 129 Posting Pro

Have you tried ValidationGroup property.?

Validation groups allow you to organize validation controls on a page as a set. Each validation group can perform validation independently from other validation groups on the page.

Check the following links.

ASP.NET ValidationGroup Property
Validation Groups in ASP.NET 2.0
Specifying Validation Groups

Ramesh S 129 Posting Pro

Do you want to this operation in client side or server side?

Since it is a web application, you can't use the above C# code at client side. It can be done using JavaScript only.

You can try to use object.execCommand javascript method to paste the text from clipboard to the current object such as TextBox.

For example,

function PasteTextFromClipboard()
        {
            document.getElementById('textArea1').focus();
            var strText = document.getElementById('textArea1').createTextRange();
            strText.execCommand("Paste");
        }

In case if you want to do this operation in server side, check the following article. The C# code uploads a word document file and stores it into a string and from that it is placed that string into a textbox.

Read any document (like .doc, .rtf , txt ) in ASP.Net , C#

Ramesh S 129 Posting Pro
Ramesh S 129 Posting Pro

Why do you set the UseSubmitBehavior property of the Button to true? Is there a specific reasone? If no, remove that property.

Ramesh S 129 Posting Pro

The built-in feature of .NET String class has methods to remove spaces in a given string. Why do you want to go for a custom method?

String str1 = "This is a string"
String str2  = str1.Replace(" ", String.Empty)

Here str2 will have the string value "Thisisastring".

Ramesh S 129 Posting Pro

You need to set index.htm as the default document in IIS.

Check this link.

Setting Up Default Documents (IIS 6.0).

If you are using a web hosting company to deploy you site over internet, you can ask them to set index.html as default document for your site.

Ramesh S 129 Posting Pro

The ASP.NET MVC Framework is a web application framework that implements the Model-view-controller pattern. It allows software developers to build a Web application as a composition of three roles: Model, View and Controller.

Check the following links to see more details.

ASP.NET MVC Tutorials
Free ASP.NET MVC eBook Tutorial

Ramesh S 129 Posting Pro

You can declare like this.

Partial Class YourPage
    Inherits System.Web.UI.Page

    Dim txtbox1 As TextBox
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtbox1 = Wizard.ContentTemplateContainer.FindControl("textbox1")
    End Sub


    Private Sub YourMethod()
        Dim str1 As String
        str1 = txtbox1.Text


    End Sub
End Class

The variable is declared at page class level. The reference of the textbox1 control is stored in page load event. It is accessed in YourMethod(). Like that you can access the variable txtbox1 in all methods in the page class.

jtok commented: Awesome post! Well put, easy to understand. Thanks! +2
Ramesh S 129 Posting Pro

Hi

Mark this thread as solved if your question is answered.

Regards
Ramesh. S

Ramesh S 129 Posting Pro

Pass the value as a query string from asp.net to php.

Also refer this link: Tips to Make ASP.NET Talk to ASP, PHP, RAILS and JAVA (Part 1)

Ramesh S 129 Posting Pro

Hi Rick Pace,

Please mark this thread solved if your question is answered.

Regards
Ramesh S

Ramesh S 129 Posting Pro

Mark this thread Solved if your question is answered.

Ramesh S 129 Posting Pro

Read this article.

Ramesh S 129 Posting Pro

Try this.

ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables ;

            cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

            crConnectionInfo.ServerName = "YOUR SERVER NAME";
            crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
            crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
            crConnectionInfo.Password = "YOUR DATABASE PASSWORD";

            CrTables = cryRpt.Database.Tables ;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();

Reference: C# Crystal Reports Dynamic Logon parameters

Also refer this link.

How to pass Database logon info to a Crystal Report at runtime in VB .NET or in C#

bill_kearns commented: Thank you! +0
Ramesh S 129 Posting Pro

Try like this.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlDataSource1.SelectCommand = "SELECT customerID, lname, fname, dateNow FROM dbo.customers ORDER BY lname ASC";
        }
    }
    protected void SqlDataSource1_Init(object sender, EventArgs e)
    {

        SqlDataSource1.SelectCommand = String.Empty;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        SqlDataSource1.SelectCommand = "SELECT customerID, lname, fname, dateNow FROM dbo.customers WHERE rep is null ORDER BY lname ASC";

    }
Ramesh S 129 Posting Pro

You can split a string into array of sub strings based on delimiter character such as space, comma.

string str = TextBox1.Text.Trim();
        string[] temp = str.Split(' '); 
        for (int j = 0; j < temp.Length; j++)
        {
                Response.Write("  This is index " + j.ToString());
                Response.Write("  This is the string : " + temp[j]);
            }

        }
Ramesh S 129 Posting Pro

Your dropdownlist bound to datasource for every submit. It should not be.

You need to check IsPostBack property on load event before binding the DropDownList.

Change your code as below

Protected Sub fillDropList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        
If Not IsPostBack Then
   DropList1.DataSource = Membership.GetAllUsers()        
   DropList1.DataBind()    
End If
End Sub
Ramesh S 129 Posting Pro

Refer this link: Global Web Stats

You can also view the statistics for past period through "View archived reports" dropdownlist in that site.

Refer this link also.

Usage share of web browsers

Ramesh S 129 Posting Pro

From your first post, it seems that you put the ChecBoxList control inside a Repeater control.

If so, you can try this code.

protected void Page_PreRender(object sender, EventArgs e)
    {
        foreach (RepeaterItem ritem in Repeater1.Items)
        {
            CheckBoxList chkList = ritem.FindControl("CheckBoxList1") as CheckBoxList;
            foreach (ListItem listitem in chkList.Items)
            {
                listitem.Attributes.Add("onclick", "alert('hey');");
            }
        }
    }

Anyway, you found a solution by yourself.

Mark this thread as solved/

Ramesh S 129 Posting Pro

Putting the CheckBoxList control inside a UpdatePanel control does not make this problem.

The CheckBoxList is implemented a collection of ListItems.

Attributes added to a ListItem control don't get rendered during postback.

Actually it is a bug in ASP.NET.

Refer the following links to know more about on this bug.

http://unboxedsolutions.com/sean/archive/2004/05/04/213.aspx
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx

To work around this issue, you need to add attributes to ListItem collection in the Page PreRender event instead of DataBound event.

Try this code.

protected void Page_PreRender(object sender, EventArgs e)
    {

        foreach (ListItem listitem in chkSides.Items)
        {
            listitem.Attributes.Add("onclick", "alert('hey');");
        }
    }
Ramesh S 129 Posting Pro

Hi jbisono,

The values of the controls will not be loaded from ViewState in PreInit event. Therefore avoid to use it.

Since it seems that you want to execute some code in master page and then some code in child pages, what you mentioned is a good idea.

jbisono commented: Smart person +1
Ramesh S 129 Posting Pro

Hi jbisono ,

I am clear about your requirement now. You may need to write code specific to the child pages in the page _load event of the master page. So that it will be executed automatically for all child pages.

You can use Page.GetType().Name or other technique like this to get the child page name in Master page and write the specifc code to it.

Alternatively you can create BasePage class and inherit all your child pages from this class.Override the OnLoad event in the BasePage and write code specific to the pages inherited from it.

Ramesh S 129 Posting Pro

Hi Stretcher,

Mark this thread as solved.

Ramesh S 129 Posting Pro

Hi Stretcher,

Welcome to DaniWeb.

Use code tags to format your code.

Why do you use Request object to get the value of TextBox control. You can use like TextBox1.Text to get the value of it.

Also you are using <form> tag inside the server controls. Basically the ASP.NET controls should be surrounded by <form> tag.

To get the value of Customer_Name textbox value from Request object, try this

Request("TabContainer1$TabPanel1$Customer_Name")
Ramesh S 129 Posting Pro

Each child web forms will have different controls. If you want to access child page controls in your master page, then you can do it something like

ContentPlaceHolder1.FindControl("Button1")

Or do you want to get master page event in your child pages? if so, refer this link.

Ramesh S 129 Posting Pro

It would be better if you store the forum messages in a database system. So that you can easily store, retrieve the data with better performance.

If you store the forum data in a datbase, you can use the features specific to database systems such as security, indexing, stored precedures, views.

You can use SQL Server 2005/2008 Express Editions, MySQL for this purpose. You can also even use MS-Access which has limited features comparing with SQL Server and MySQL.

If you have a plan to use open source forum software, please check which database are supported by that software.

Ramesh S 129 Posting Pro

Mark this thread as Solved if your question is answered.