Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all 956 articles
Browse latest View live

How to store the selected values of a group of check boxes in to database using asp.net (c#)

$
0
0

hi,

How to store the selected values of a group of check boxes in to database using asp.net (c#). 

Eg: storing the hobbies selected by the user while registering, in to database.

--bdhkrl.


SqlDataSource Selecting/Selected events not firing

Wild Card Search in Asp:Repeater

$
0
0

hello

i have a repeater control i want to search Repeaters record (wild card search) usng text box

how can i do this using json / jquerty / javascript

Assign returned value to a label

$
0
0

Hi pals,

I have the following code:

string connect = "SomeConnectionString";
        SqlConnection con = new SqlConnection(connect);
        var cmd = new SqlCommand("SELECT COUNT(DISTINCT parent) AS Expr1 FROM Menus", con);
        cmd.Connection.Open();
        SqlDataReader reader = cmd.ExecuteReader();

         /*
             Assign the returned value to Lable1.text
         */

        reader.Close();
        cmd.Connection.Close();
        cmd.Dispose();

The result drawn from the command is an integer value stored in a column named "Expr1".

My question is: How can I assing the returned value to Label1.text?

Query timeout but no error?

$
0
0

Hello all, i have this query that i have stored as a function on the db and call it via sqldatasource.  The query is big and works in the test environment but not in ptoduction, it produces no timeout error message it just doesnt render the grid at all (which is a Radgrid BTW).  This is what i've done so far.  The query works i tested it on management studio on the production machine although it took 44 seconds, it did compile.  Any ideas/Help appreciated!

protected void SqlGrade9CH4_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.CommandTimeout = 0;
        }

in the connnection string of the webconfig i added..

Connection Timeout=60

 

 

Assign different values to an array of struct

$
0
0

Hi pals,

I have a table ("Menus") with the follwoing attributes: 

Id(int), name(nvarchar), parent(int), path(nvarchar)

and a struct named ("menusData"). I am going to assign the data in the table to an array of the struct. The following is the code. But unfortunately, I don't know how to assing Int types and nvarchar types. The following code throws an exception! Please help me with the problem:

protected struct menusData
    {
        public int id, parent;
        public string name, path;
    }
    protected menusData [] myMenu = new menusData[100];
    protected int noMyMenu = 0;


protected void fillData()
    {
        string connect = "SomeConnectionString";
        SqlConnection con = new SqlConnection(connect);
        var cmd = new SqlCommand("SELECT * FROM Menus", con);
        cmd.Connection.Open();

        SqlDataReader reader = cmd.ExecuteReader();

        if (reader.Read())
        {
            myMenu[noMyMenu].id = (Int16)reader.GetInt16(0);      //0 = id column
            myMenu[noMyMenu].name = (string)reader.GetString(1);  //1 = name column
            myMenu[noMyMenu].parent = (Int16)reader.GetInt16(2);  //2 = parent column
            myMenu[noMyMenu].path = (string)reader.GetString(3);  //3 = path column
        }
        
        reader.Close();
        cmd.Connection.Close();
        cmd.Dispose();
    }

Full-text index search not returning expected results

$
0
0

Hello,

My full-text search isn't working at all! I have a temporary table with full-text indexing enabled where files are scanned for social security numbers. If it has one, the user will see a message that it believes it's found a SSN and won't upload it. There is only ever one row in this table, as we overwrite the contents upon each upload.

I'm testing this search, and it doesn't work. The table has the following columns:
attachemtId (int) - primary key
fileContent (image) - contents of the file
fileExtension (varchar) - extension of the file (this is always either ".pdf" or ".doc")

I created a .doc file that simply says "ssn", and then run the following query:

SELECT * FROM TempAttachment
WHERE CONTAINS(fileContent,'ssn')

and nothing is returned! I tried the same thing with a .pdf file, and same results.

I'm not sure if this is related, but earlier I had this issue where I had to reset permissions for the directory. I've tried removing the full-text index and adding it again, but that didn't do anything. I also checked error logs on the server, and there were no messages. Any help would be appreciated! Thank you!

Differences between contains and containstable

$
0
0

Hi,

I have the following queries that should be technically equivalent:

select * from ProductSearchIndexData psid
where Product_ID = 946 and contains(psid.[Text], '("exp*")')

SELECT [key] as id, rank
FROM CONTAINSTABLE(ProductSearchIndexData, [Text], '("exp*" )')
where [key]= 946

The first one returns the right result, the second returns none.

Is there anything I am missing here?

Thanks!


How to assign timed out value for the Table Adapter in VB NET 2.0

$
0
0

Hi Guys,

Currently i am using VB NET 2.0, and my connection to SQL Server are by wizard, which is Table Adapter, here is my current code:-

As usual, after the wizard, i having a xsd file, example that is #MyTable.xsd#

I have a table adapter called #Student_TableAdapter#

Then i have a database function in my table adapter, which is #Change_name#

In my code, i call the function by this way:-

********

Dim adapterTable1 As New Student_TableAdapter

adapterTable1.Change_name("new name")

********

However, i can't find any attributes to set my command timeout, is there any sample code?

ASP.NET App_Code Visual Database components

$
0
0

Hi,

I am working on web based application that has in App_Code file with extension .vb

When I right click this file I have options

- View Code

- View Designer

When clicking View Designer I can see list of multiple visual components (sqlCommands, sqlConnections,etc).

Questions

- How can I generate such file?  (I am not very familiar with visual components, would like to test them first)

- How can I add new component to the list (cannot find anything on toolbox, so far I was able just to copy and paste existing components)

 

How to import an mdf file into SQL Server Management Studio Express?

$
0
0

Hi

I had to recover my computer but before I did that I grabbed a new version of my mdf file but I don't know how to actually import it into SQL Server Management Studio Express evertime I try to open the file up it just crashes.

 I rather not have to redue that whole database again. I am a noob so step by step instructions are needed.

 

Thanks
 

Problem with dynamic menu and database

$
0
0

Hi pals,

I have created a page named "CreatePage.aspx" in which I can create a new page and also attach its title, link, and parent link to the database table "enMenu". When adding such information into the table, I want my menu bar to be updated. For this section, I found an article (http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site), and I changed the "AddDynamicNodes" method according to mine, dynamically from the database table and it became like this:

        protected struct menusData
        {
            public int id, parent;
            public string name, path;
        }

        protected struct AddChild
        {
            public XmlElement addIt;
            public int myId;
        }
        protected menusData[] myMenu = new menusData[100];
        protected int noMyMenu = 0;
        protected int[] par = new int[20];
        protected int noPar = 0;
        protected AddChild[] addChild = new AddChild[100];
        protected int noAddChild = 0;

        private void AddDynamicNodes(XmlElement rootElement)
        {
            //The data from enMenu table is copied into myMenu
            CopyIntoArray();
            
            //The rest of the code adds parent and children nodes. If one node's parent is 0, that node is a main node

            for (int i = 0; i < noMyMenu; i++)
            {
                if (myMenu[i].parent == 0)
                {
                    if (!isAParent(myMenu[i].id))
                        AddDynamicChildElement(rootElement, myMenu[i].path, myMenu[i].name, "");
                    else
                    {
                        addChild[noAddChild].addIt = AddDynamicChildElement(rootElement, myMenu[i].path, myMenu[i].name, "");
                        addChild[noAddChild].myId = myMenu[i].id;
                        noAddChild++;
                    }
                }
            }


            for(int i = 0; i < noAddChild; i++)
            {
                for(int j = 0; j < noMyMenu; j++)
                {
                    if(myMenu[j].parent == addChild[i].myId)
                    {
                        if (!isAParent(myMenu[j].id))
                            AddDynamicChildElement(addChild[i].addIt, myMenu[j].path, myMenu[j].name, "");
                        else
                        {
                            addChild[noAddChild].addIt = AddDynamicChildElement(addChild[i].addIt, myMenu[j].path, myMenu[j].name, "");
                            addChild[noAddChild].myId = myMenu[j].id;
                            noAddChild++;
                        }
                    }
                }
            }

        }

        protected bool isAParent(int x)
        {
            for (int i = 0; i < noMyMenu; i++)
                if (myMenu[i].parent == x)
                    return true;
            return false;
        }
        protected void CopyIntoArray()
        {
            string connect = "someConnectionString";
            SqlConnection con = new SqlConnection(connect);
            var cmd = new SqlCommand("SELECT * FROM enMenu", con);
            cmd.Connection.Open();

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                myMenu[noMyMenu].id = Int32.Parse(reader[0].ToString());
                myMenu[noMyMenu].name = reader[1].ToString();
                myMenu[noMyMenu].path = reader[2].ToString();
                myMenu[noMyMenu].parent = Int32.Parse(reader[3].ToString());
                noMyMenu++;
            }
            reader.Close();
            cmd.Connection.Close();
            cmd.Dispose();
        }

This peice of code works absolutely correctly when thepage is run and the menu is correct. When I add a page, for example "test.aspx", it is created and its link and title are inserted into the database. The problem is that this new page, "test.aspx" is not shown in the menu bar!!! In other words, it is created, but not shown in the menu.

I had this problem when running the website on my local server, but when I restarted the project, the page was shown on the menu. But when I deploy the website on a server on the Internet, it has still the problem. It seems the above code runs just once!!! I was wondering if you'd mind helping me to solve the problem.

tnx a million

variable name has already been declared. Variable names must be unique within a query batch or stored procedure

$
0
0

i'm getting the error "variable name '@old_resource_type' has already been declared"

why does the command.Parameters.Clear() doesn't work?

thanks...

public static void Add_Resource_type(string name, string matter, string storage)
{
try
{
conn.Open();
string query_code = string.Format("SELECT Resource_type FROM [Waste2Enegy2].[dbo].[Code]");
command.CommandText = query_code;
Object reader = command.ExecuteScalar();
int code;
code = (int)reader;

string query_code_update = string.Format("UPDATE [Waste2Enegy2].[dbo].[Code] SET Resource_type=@new_resource_type WHERE Resource_type=@old_resource_type");
command.Parameters.Add("@old_resource_type", code);
command.Parameters.Add("@new_resource_type", code + 1);
command.CommandText = query_code_update;
command.ExecuteNonQuery();
command.Parameters.Clear();

string query = string.Format("INSERT INTO [Waste2Enegy2].[dbo].[Resource_Type] VALUES ('{0}', '{1}', '{2}', '{3}')", "RT" + code, name, matter, storage);
command.CommandText = query;
command.ExecuteNonQuery();

}
finally
{
conn.Close();
}
}

Error While connecting to the mysql database ... Need a solution for this problem ASAP... Please...

$
0
0


Connector/Net no longer supports server versions prior to 5.0
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Connector/Net no longer supports server versions prior to 5.0

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NotSupportedException: Connector/Net no longer supports server versions prior to 5.0]
MySql.Data.MySqlClient.NativeDriver.Open() +1307
MySql.Data.MySqlClient.Driver.Open() +22
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +210
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +289
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +113
MySql.Data.MySqlClient.MySqlPool.GetConnection() +72
MySql.Data.MySqlClient.MySqlConnection.Open() +555
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +52

[EntityException: The underlying provider failed on Open.]
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +161
System.Data.EntityClient.EntityConnection.Open() +98
System.Data.Objects.ObjectContext.EnsureConnection() +81
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +46
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
web.Repository.GetRecords(String str) in D:\jay\DavionFinal\web\Repository.cs:123
web.Search.showdata() in D:\jay\DavionFinal\web\Search.aspx.cs:59
web.Search.Page_Load(Object sender, EventArgs e) in D:\jay\DavionFinal\web\Search.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

sqlconnection usage

$
0
0
Hi,
I have dataobject classes which all call a dbconn object function eg GetData(strSQL as string) which returns a datatable which is then used by my data objects.
I wanted to know within the dbConn class (object) should I have a global connection whch I keep opening or closing or just within the function create a new instance  connect and then close?

Thanks



Help regarding GridView

$
0
0

I am working on Movie Reservation System project. I need help with Seating plan arrangement.

I am trying to poupulate gridview with image buttons. I am able to do so with itemtemplate field, but the problem is that I need to change 

the image on selection of seat and also I need that particular Row and column selected. Can anyone help me please. 

The argument types 'Edm.String' and 'Edm.Int32' are incompatible for this operation., near addition operation

$
0
0

 

 

 

 

 

<

asp:EntityDataSourceID="dsSic"

 

AutoGenerateOrderByClause="true"

 

ContextTypeName="BaseLib.Data.DataContext"

 

EntitySetName="CategorySet"

 

Select="it.Id, '[' + it.Id + '] - ' + it.Name as BaseName"

 

</

 

runat="server">asp:EntityDataSource>

 

I'm getting the following error:The argument types 'Edm.String' and 'Edm.Int32' are incompatible for this operation., near addition operation

 

What's the correct way to write this Select statement? Thanks!

error: the provider did not return a ProviderManifest instance

$
0
0

Hi

I've started a webform project and when I drop a EntityDataSource on the page and want to configure it with selecting Named Connection, there is a message that says:

the metadata specified in the connection string could not be loaded. Consider rebuilding web project to build assemblies that may contain metaddata. the following errors ocurred:

the provider did not return a ProviderManifest instance

I rebuild and closed the solution and opened it again but nothing changed. I searched this forum but nothing found and also searched the web and It seems this problem continues from VS 2008. Please Help.

I'm using VS2013.1

Thanks

Objectdatasource select parameters in n-tier

$
0
0
I'm writing an asp.net application with gridview using objectdatasource. There are number if text box fields on the form for the user to search on.
I've setup the objectdatasource with a BLL and select parameters. So it passes 10 parameters, but then I need to pass those 10 parameters to the DAL.

Is there any versatile way to do this rather pass all the variables?what is the Best Practise? Perhaps into an object class?

Cannot pass datetime value programmatically through SqlDataSource to Access 2013 database

$
0
0

ASP.NET form:

<asp:SqlDataSource ID="dsLoan" runat="server" ConnectionString="<%$ ConnectionStrings:connLibrarySystem %>"
                ProviderName="<%$ ConnectionStrings:connLibrarySystem.ProviderName %>"
                SelectCommand="SELECT TOP 1 LOAN.LoanID FROM (BOOKS INNER JOIN LOAN ON BOOKS.ACCESSION = LOAN.ACCESSION) WHERE (BOOKS.ACCESSION = @Accession) ORDER BY LOAN.LoanID DESC"
                UpdateCommand="UPDATE LOAN SET DATE_OF_RETURN = @ReturnDate, OverDate = 3 WHERE (LOAN.LoanID = @LoanID)"><SelectParameters><asp:ControlParameter ControlID="tbAccession" Name="Accession" PropertyName="Text" Type="String" /></SelectParameters><UpdateParameters><asp:SessionParameter SessionField="LoanID" Name="LoanID" Type="Int32" /><asp:Parameter Name="ReturnDate" Type="DateTime" /></UpdateParameters></asp:SqlDataSource>

C# Function

protected void btnBookReturn_Click(object sender, EventArgs e)
    {
        // Select the latest LoanID based on the specified Book Accession
        int loanID = int.Parse((this.dsLoan.Select(DataSourceSelectArguments.Empty) as DataView).Table.Rows[0]["LoanID"].ToString());
        Session["LoanID"] = loanID;

        // Update the Return Date of the corresponding loan record to today
        this.dsLoan.UpdateParameters["ReturnDate"].DefaultValue = DateTime.Today.ToShortDateString();

        // Update the Loan record
        this.dsLoan.Update();

After the update is completed, the Overdate column in the target record is updated but the DATE_OF_RETURN column remains unchanged.

Even if I have insert the following code snippet inside the SqldDataSource and update the C# code as belows,

OnUpdating="dsLoan_Updating"
    protected void dsLoan_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters["ReturnDate"].Value = DateTime.Today;
    }

The problem still occurs.

Please advice how to solve this problem. Thanks in advance.

Viewing all 956 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>