Category Archives: AccessDataSource

AccessDataSource

[RESOLVED]Error delete and edit in gridview

i am writing a code below which is used in my gridview (asp.net+vb web with access database)

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ ConnectionStrings:baijuepConnectionString %>"
                    
                    SelectCommand="SELECT * FROM [Tasks]"
                    DeleteCommand="delete [Tasks] where id=@id"
                    
                    UpdateCommand="update  [Tasks] set TaskDescription=@TaskDescription,StartDate=StartDate,EndDate=@EndDate,Notes=@Notes where id=@id"
                    ProviderName="<%$ ConnectionStrings:baijuepConnectionString.ProviderName %>">
                    <SelectParameters>
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="id" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="TaskDescription" />
                        <asp:Parameter Name="StartDate" />
                        <asp:Parameter Name="EndDate" />
                        <asp:Parameter Name="Notes" />
                    </UpdateParameters>
                </asp:SqlDataSource>

when i click edit button in my gridview and ammend something and press update the data is not updated

and the delete button gives eror as

Syntax error (missing operator) in query expression ‘[Tasks] where id=@id’.

I think your Update "parameters" section needs to include the "ID" variable, as in;

<UpdateParameters>
   <asp:Parameter Name="TaskDescription" />
   <asp:Parameter Name="StartDate" />
   <asp:Parameter Name="EndDate" />
   <asp:Parameter Name="Notes" />
   <asp:Parameter Name="ID" />
</UpdateParameters>

I don’t see anything in the Delete mechanism that could be causing an error, so maybe the missing ID in the Update is failing over to the Delete event.

But, try repairing the Update Parameter, and see if that helps.

added ID in update parameter still not updating

Did you really want StartDate=StartDate in your UpdateCommand?  Also, if I recall correctly, use a ? instead of @ to pass parameters in Access, so try:

UpdateCommand="update  [Tasks] set TaskDescription = ?, StartDate = ?, EndDate= ?, Notes = ? where id = ?"

 

Also, why are you using an SQLDataSource, instead of an AccessDataSource?

<asp:AccessDataSource ID="AccessDataSource" runat="server"
  DataFile="~/myAccessDatabase.mdb"
  SelectCommand="SELECT * FROM [Tasks]"
  DeleteCommand="delete [Tasks] where id=?"
  UpdateCommand="update  [Tasks] set TaskDescription = ?, StartDate = ?, EndDate= ?, Notes = ? where id = ?"
 <DeleteParameters>
  <asp:Parameter Name="id" />
 </DeleteParameters>
 <UpdateParameters>
  <asp:Parameter Name="TaskDescription" />
  <asp:Parameter Name="StartDate" />
  <asp:Parameter Name="EndDate" />
  <asp:Parameter Name="Notes" />
  <asp:Parameter Name="id" />
 </UpdateParameters>
</asp:AccessDataSource>

i changed as per ur direction

edit update works fine but delete gives following error

Syntax error (missing operator) in query expression ‘[Tasks] where id=?’.


Try:

DeleteCommand="delete FROM [Tasks] where id = ?"

I’m not sure if you need the *, like delete * FROM [Tasks] where id = ?

 

[RESOLVED]Gridview data view

in my web page there is text boxes to insert data to database and a gridview below that to view the insertde data. the data gets inserted correctly but the data is not immediately viewed in the gridview it needs refresh page or reload how can it be rectified

Make sure you are calling GridView.DataBind() after you insert the data and update the GridView.DataSource.

On the same event you have for inserting data you need to rebind your grid.

So if you have

cmdSave_Click{

 // code o add data

gvGridviewName.DataSource = dsName;
gvGridviewName.DataBind(); 

}

Make sure you’re binding the grid at the right time/event. 

i am using sqldatasource with select command in .aspx page and wrote the code like this after  .vb code page 

 GridView1.DataBind()

still that last entry is not viewed in the grid the second last entry is shown

when enter one more row then the previous data is viewed

Try calling SqlDataSource1.DataBind() before GridView1.DataBind().  Also make sure  EnableCaching = "False" on the SqlDataSource control.

Call the BindGridView() function as the last statement in the  save button click.

For reference check the article Bind,Save,Edit,Update,Cancel,Delete,Paging
example in GridView in asp.net C#

if you are using VB language then read How
to Bind,Insert,Edit,Update,Delete in GridView in asp.net VB.Net

not yet solved

i am using a code behind to insert new data to gridview

and the databinding is done by sqldatasource update,edit code

Baiju EP

not yet solved

i am using a code behind to insert new data to gridview

and the databinding is done by sqldatasource update,edit code

Could you post the code behind here where you insert the new data and databind, so we can see the actual code calls?

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New OleDbConnection
        con.ConnectionString = ConfigurationManager.ConnectionStrings("baijuepConnectionString").ConnectionString
        con.Open()
Dim oledb_ins As String
        oledb_ins = "insert into Tasks (TaskDescription, startdate, enddate, Notes) values (@a,@b,@c,@d)"
        Dim oledbcom As New OleDbCommand(oledb_ins, con)
        oledbcom.Parameters.Add(New OleDbParameter("@a", OleDbType.VarChar, 50)).Value = tasktxt.Text
        oledbcom.Parameters.Add(New OleDbParameter("@b", OleDbType.VarChar, 50)).Value = startdt.Text
        oledbcom.Parameters.Add(New OleDbParameter("@c", OleDbType.VarChar, 50)).Value = enddt.Text
        oledbcom.Parameters.Add(New OleDbParameter("@d", OleDbType.VarChar, 50)).Value = notestxt.Text
        oledbcom.ExecuteNonQuery()
        tasktxt.Text = ""
        startdt.Text = ""
        enddt.Text = ""
        notestxt.Text = ""
        SqlDataSource1.DataBind()
        GridView1.DataBind()
Page.ClientScript.RegisterStartupScript(Me.GetType, "Forms", "<script> alert('Record Inserted Succesfully ..........') </script>")

ens usb

sqldatasource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:baijuepConnectionString %>" 
                    
                    SelectCommand="SELECT * FROM [Taskss]" 
                    DeleteCommand="delete [Tasks] where id=@id" 
                    
                    UpdateCommand="update  [Tasks] set TaskDescription=@TaskDescription,StartDate=StartDate,EndDate=@EndDate,Notes=@Notes where id=@id" 
                    ProviderName="<%$ ConnectionStrings:baijuepConnectionString.ProviderName %>">
                    <SelectParameters>
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="id" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="TaskDescription" />
                        <asp:Parameter Name="StartDate" />
                        <asp:Parameter Name="EndDate" />
                        <asp:Parameter Name="Notes" />  
                        <asp:Parameter Name="id" />                                                
                    </UpdateParameters>
                </asp:SqlDataSource>

the data get inserted into the database but not displying in the gridview at once

it gets viewed when one more entry is made how can it be possible

and with the edit/delete in grid it is also not working

i was not able to solve the problem

I noticed in your SqlDataSource you have

 SelectCommand="SELECT * FROM [Taskss]" 

it should be

SelectCommand="SELECT * FROM [Tasks]"

Other than that it should work. If that was just a copy paste typo into this forum and it is [Tasks] in your actual code already then maybe it’s some kind of screen refresh issue. Are you using an Ajax UpdatePanel or something?  After you click the button
and the record is not there does it show up if you hit ctrl-F5?

For Gridview edit make sure you have DataKeyNames="id" in your GridView.

I  had corrected it still it is not displaying when the new record is added . when one more record is added then the previous recod gets displayed

Baiju EP

I  had corrected it still it is not displaying when the new record is added . when one more record is added then the previous recod gets displayed

When you add a new record and the previous record gets displayed, does the new record show if you press ctrl+F5 in your browser?

yes when i add a record and press refresh the dtata gets displayed

In your markup are you using Ajax or an UpdatePanel?  If so make sure your insert Button and GridView are in the same UpdatePanel or Ajax call.

i am using accessdatasource to all actions. select, insert,update,delete code all are in accessdatasource

Hi Baiju EP,

Based on your description I have created a sample,  I find it can work fine, I also find a mistake in your code:
the “SelectCommand="SELECT * FROM [Taskss]"”  T-SQL statement which select data from “Taskss”, but in behind code, you have insert data into “Tasks”, so please check you table name again.

The following is my sample code, please try to refer to it.

In the .aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="GridViewDataView.WebForm1" %>

 

<!DOCTYPE html>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:SqlDataSource ID="SqlDataSource2" runat="server"

            ConnectionString="<%$ ConnectionStrings:DemoDBConnectionString %>"

            SelectCommand="SELECT [Id], [name], [age], [sex] FROM [Student]"

            UpdateCommand="Update Student set name = 'Mr. OK'"

            DeleteCommand="Delete Student"></asp:SqlDataSource>

        <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="Id">

            <Columns>

                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />

                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

                <asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />

                <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />

            </Columns>

 

        </asp:GridView>

        <asp:Button runat="server" Text="Insert one record" OnClick="Insert_Click" />

    </div>

    </form>

</body>

</html>

In the .aspx.cs:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Configuration;

using System.Data.SqlClient;

 

namespace GridViewDataView

{

    public partial class WebForm1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

        }

 

        protected void Insert_Click(object sender, EventArgs e)

        {

            string connStr = ConfigurationManager.ConnectionStrings["DemoDBConnectionString"].ToString();

            SqlCommand cmd = new SqlCommand("insert into Student values(@Id,@name,@age,@sex)", new SqlConnection(connStr));

            SqlParameter[] parameters = new SqlParameter[] {

                new SqlParameter("@Id",5),

                new SqlParameter("@name","Andy"),

                new SqlParameter("@age",24),

                new SqlParameter("@sex","male")

            };

            foreach (SqlParameter p in parameters)

            {

                cmd.Parameters.Add(p);

            }

            if (cmd.Connection.State == System.Data.ConnectionState.Closed)

            {

                cmd.Connection.Open();

            }

           if (cmd.ExecuteNonQuery() > 0)

            {

                SqlDataSource2.DataBind();

                GridView1.DataBind();

                Page.ClientScript.RegisterStartupScript(this.GetType(), "Forms", "<script> alert('Record Inserted Succesfully ..........') </script>");

            }

            if (cmd.Connection.State == System.Data.ConnectionState.Open)

            {

                cmd.Connection.Close();

            }

        }

    }

}

Best Regards,
Terry Guo

[RESOLVED]cascading checkboxlist

Hi all,

let say i hv 2 checkboxlists which are A and B,

-Both control connected tthrough AccessSourceControl to same table.

-selection on A will filter the B result.

I now having problem in configure the data source on B since the WHERE Clause do not have IN as the checklistbox can be multiple seletion.

The Operator only consists of "Like, Contains …" which cant support the multiple selection on Control A right?

please guide.

You can pass string from combination selected checkboxlist text.

Use Stored Procedure to generate WHERE Clause

Stored procedure? can explain more?

anyone?

<asp:AccessDataSource ID="adsResult" runat="server"
        DataFile="~/App_Data/DataFeed.mdb"
        
        SelectCommand="SELECT * FROM [pc_status] WHERE ([mycolumn] in (Select [mycolumn] From dbo.Split(@[mycolumn], ',')))">
        <SelectParameters>
    
            <asp:ControlParameter ControlID="myListBox1"
                Name="mycolumn"  DefaultValue="0" PropertyName="SelectedValueList"/>
        </SelectParameters>
    </asp:AccessDataSource>

it give me error as follows…

System.Data.OleDb.OleDbException: Syntax error. in query expression ‘([mycolumn] in (Select [mycolumn] From dbo.Split(@[mycolumn], ‘,’)))’.

When the user selects in the first checklist box then you will refresh the second list based on the first selection.

Items.Add will work to read the selected values.

Hi,

Please refer to

http://forums.asp.net/p/1588730/4029248.aspx#4029248.

Any more question, please feel free to reply.

[RESOLVED]Grid view refresh after button submit

in my asp.net+vb web with access database. i have gridview. i had added a form with submit button to add the data in gridview.

i am using accessdatasource to bind the data to gridview. 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                                     "Data Source=C:webauth.mdb"
        Dim con As OleDbConnection = New OleDbConnection(connectString)
        con.Open()Dim sql_ins As String
        sql_ins = "insert into tasks (Appt,Task,Actionby,Complete,Remark) values (@a,@b,@c,@d,@e)"
        Dim oledbcom As New OleDbCommand(sql_ins, con)
        oledbcom.Parameters.Add(New OleDbParameter("@a", OleDbType.VarChar, 8)).Value = DropDownList1.Text
        oledbcom.Parameters.Add(New OleDbParameter("@b", OleDbType.VarChar, 50)).Value = tasktxt.Text
        oledbcom.Parameters.Add(New OleDbParameter("@c", OleDbType.VarChar, 50)).Value = DropDownList2.Text
        oledbcom.Parameters.Add(New OleDbParameter("@d", OleDbType.Date)).Value = comptxt.Text
        oledbcom.Parameters.Add(New OleDbParameter("@e", OleDbType.VarChar, 50)).Value = rmk.Text
        oledbcom.ExecuteNonQuery()
        GridView1.DataBind()
        tasktxt.Text = ""
        comptxt.Text = ""
        DropDownList1.Text = "Select"
        DropDownList2.Text = "Select"
        Page.ClientScript.RegisterStartupScript(Me.GetType, "Forms", "<script> alert('Record Inserted Succesfully .........') </script>")
    End Sub

even after the data inserted message flshes the data inserted is not viewed in the gridview . when i press F% or refresh tha page the gets displayed in gridview. how can i solve the problem

You call databind on the grid but perhaps you need to set the DataSource property prior to calling databind. 

i had tried it accessdatasource1.DataBind()

GridView1.DataBind()

not working

use !isPostPack 

pageLoad()

{

if( !IsPostPack)

{

//Some code

accessdatasource1.DataSource=dbreturn value;//

GridView1.DataBind()

}

}

HI Baiju,

In your code on click of button, you are inserting your data into the table. But in order to get updated data which is present in the table, you again need to fetch data from the table and then bind the grid view with that updated data. 

How can i do it

How can i do it

Hi Baiju,

You would be displaying records on your gridview on your page before this Button Click. Might be either on your page load. Could you please post your whole page code so that i can tell you. Find on your page, you would be assigning a datasource to gridview
like

GridView1.DataSource

i am binding my data to gridview through accessdatasource

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
                    DataFile="C:webeme_auth.mdb" SelectCommand="SELECT * FROM [Tasks] WHERE Remark Not Like 'Yes' order by complete"
                    
                    UpdateCommand="UPDATE Tasks SET Appt =@Appt, Task =@Task, Actionby =@Actionby, Complete =@Complete, Remark =@Remark WHERE Id =@Id"
                    DeleteCommand="DELETE FROM [Tasks] WHERE id=id">
                 <UpdateParameters>
                        <asp:Parameter Name="Appt" />
                        <asp:Parameter Name="Task" />
                        <asp:Parameter Name="Actionby" />
                        <asp:Parameter Name="Complete" />
                        <asp:Parameter Name="Remark" />
                    </UpdateParameters>
                </asp:AccessDataSource>

and the code behind to insert data to database is posted in the first post in this page

Hi Baiju_EP

According to your description, I have created a sample, and it can work fine, it may help you, please try to refer to the following sample code.

In the aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="InsertValueToGridView.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button" runat="server" OnClick="Button_Click" Text="Click" />
        <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:DemoDBConnectionString %>" SelectCommand="SELECT * FROM [Student]" >
        </asp:SqlDataSource>
        <asp:GridView runat="server" DataSourceID="SqlDataSource1" ID="GridView"></asp:GridView>
    </div>
    </form>
</body>
</h

In the aspx.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace InsertValueToGridView
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=(localdb)Projects;Initial Catalog=DemoDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
            SqlCommand cmd = new SqlCommand();
            string sql = "insert into Student values(@id,@name,@age,@sex)";
            cmd.CommandText = sql;
            cmd.Connection = conn;
            SqlParameter[] para = new SqlParameter[]{
                new SqlParameter("@id",11),
                new SqlParameter("@name","test"),
                new SqlParameter("@age",22),
                new SqlParameter("@sex","male")
            };
            foreach (SqlParameter p in para)
            {
                cmd.Parameters.Add(p);
            }
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            cmd.ExecuteNonQuery();
            SqlDataSource1.DataBind();
            GridView.DataBind();
        }
    }
} 

Best Regards,
Terry Guo

[RESOLVED]Query for Gridview in asp.net+vb

In my asp.net+vb+access database web. i have a gridview with accessdatasource. i want to pull out a count function from two tables

AUTH (table) in this table  TCAO is the qualification. it means this tables shows the diffrenet section who should have TCAO qualified persons

Section         TCAO    

Sneeker           2

Polo                1

Walls               2

Tango              2 

PERS (Table)

PNO                Name                 Section                 Course

k321                Sony                   Sneeker                MBA, CDAC, BE(CS), TCAO

h123               Ashok                  Polo                     BA,LLB,BE(MECH)

y432               Baiju                    Walls                    BTECH(CS,CCNA,TCAO

u789               Pooja                  Tango                   CCNA,SQA,HITECH

k765               sonu                    Sneeker                hitech,tata,leyland

I want to display the data in gridview as under

Section           Sction.TCAO        TCAO(This is the count from pers table how much persons are qualified in TCAO in that section)

Sneeker           2                         1           

Polo                1                         0

Walls               2                         1

Tango              2                         0

 i tried a lot with left join and all but the result was not gained

Try this query,

SELECT
	au.Section, au.TCAO,
	'Count_TCAO' = (SELECT COUNT(p1.Section) FROM PERS AS p1 WHERE p1.Section = au.Section
			AND p1.Course LIKE '%TCAO%')
 FROM AUTH AS au
INNER JOIN PERS AS pe ON au.Section = pe.Section
GROUP BY au.Section, au.TCAO

When i run the query message comes that enter parameter value

Count_TCAO

Try the updated one above.

tried it

Expr1002 heading and error in all rows

Are you getting this error message in SQL server?

my database in i access

SELECT    AUTH.Section,
          AUTH.TCAO AS Sect_TCAO,
          IIF(P.TCAO IS NULL, 0, P.TCAO) AS TCAO
FROM      AUTH
LEFT JOIN (SELECT   Section,
                    Count(*) AS TCAO
           FROM     PERS
           WHERE    Course Like '%TCAO%'
           GROUP BY Section) AS P ON AUTH.Section = P.Section

Out put of this query which i got is as under

Section     Sect_TCAO     TCAO

in this section and Sect_TCAO is correct but The Field TCAO shows zero for all section as it should show the count of persons qualified in TCAO of that section

Baiju EP

Out put of this query which i got is as under

Section     Sect_TCAO     TCAO

in this section and Sect_TCAO is correct but The Field TCAO shows zero for all section as it should show the count of persons qualified in TCAO of that section

I think you’re testing this in Access? In Access, the wildcard character is *, so to test this in Access, the querry must be modified to:

SELECT    AUTH.Section,
          AUTH.TCAO AS Sect_TCAO,
          IIF(P.TCAO IS NULL, 0, P.TCAO) AS TCAO
FROM      AUTH
LEFT JOIN (SELECT   Section,
                    Count(*) AS TCAO
           FROM     PERS
           WHERE    Course Like '*TCAO*'
           GROUP BY Section) AS P ON AUTH.Section = P.Section

 

is it possible to add two more clause in this query. itried a lot but not got through

There is a field named outdetails in the Pers Table. in which transfers are maintained

if a person is transferd to another section then the section name and date of move is entered in th outdetails field in Pers table

OutDetails like pers.section (it is OUT)

 outdetails not like pers.section (it is IN) but the problem is the persons are coming IN from another section’s their outdetails will be filled in their section outdetails coloumn and not in front of the section in which they are joining

Please show some example data and desired result?

Section         TCAO    

Sneeker           2

Polo                1

Walls               2

Tango              2 

PERS (Table)

PNO                Name                 Section                 Course                                   Outdetails

k321                Sony                   Sneeker                MBA, CDAC, BE(CS), TCAO        POLO by 21 Ayg 2013

h123               Ashok                  Polo                     BA,LLB,BE(MECH)                     

y432               Baiju                    Sneeker               BTECH(CS,CCNA,TCAO              Tango by 23 Aug 2013

u789               Pooja                  Tango                   CCNA,SQA,HITECH                  

k765               sonu                    Sneeker                hitech,tata,leyland

I want to display the data in gridview as under

Section           Sction.TCAO        TCAO      TOUT        TIN            Held (TACO-TOUT+TIN)

Sneeker           2                         2           2                 0               0

Polo                1                         0           0                 1               1

Walls               2                         0          0                 0                0

Tango              2                         0          0                 1               1

The held is TCAO -TOUT(Persons moving out) + TIN (Persons comming in from other section)

i had posted it but not visible due to moderators approval is pending

SELECT      Section,
            Sect_TCAO,
            TCAO,
            TOUT,
            TIN,
            TCAO - TOUT + TIN AS Held
FROM        (SELECT      A.Section,
                         A.TCAO AS Sect_TCAO,
                         IIf(P1.TCAO Is Null,0,P1.TCAO) AS TCAO,
                         IIf(P2.TOUT Is Null,0,P2.TOUT) AS TOUT,
                         IIf(P3.TIN Is Null,0,P3.TIN) AS TIN
             FROM        ((AUTH AS A
             LEFT JOIN     (SELECT   Section,
                                     Count(*) AS TCAO
                            FROM     PERS
                            WHERE    Course Like '*TCAO*'
                            GROUP BY Section) AS P1 ON A.Section = P1.Section)
             LEFT JOIN    (SELECT   Section,
                                    Count(*) AS TOUT
                           FROM     PERS
                           WHERE    IIF(Outdetails Is Null, '', Outdetails) <> ''
                           GROUP BY Section) AS P2 ON A.Section = P2.Section)
             LEFT JOIN   (SELECT Section,
                                (SELECT COUNT(*)
                                 FROM   PERS
                                 WHERE  Outdetails Like '*' & AUTH.Section & '*') AS TIN
                          FROM AUTH) AS P3 ON A.Section = P3.Section)

[RESOLVED]How to add ajax tabcontainer inside gridview in asp .net

Hi,

I need to add tabcontainer inside a gridview which retrives data from sql server.Could you please help me to do this?
Currently iam getting the following error in the gridview
"
Couldnot find any resources appropriate for the specified culture or the neutral culture.makesure "AjaxControlToolkit.propertied.resources.resources"was correctly embedde or linkined into assembly"AjaxControlToolkit"atcompile time,or that all the satellite
assemblies required are loadable and fully signed."

This is the code i have given

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            PageSize="6" Height="1173px" Width="705px"
            onselectedindexchanged="GridView1_SelectedIndexChanged">
       <Columns>
       <asp:TemplateField>
       <ItemTemplate>
      
        <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="2">
        <ajaxToolkit:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
        </ajaxToolkit:TabPanel>
        <ajaxToolkit:TabPanel runat="server" HeaderText="TabPanel2" ID="TabPanel2">
        </ajaxToolkit:TabPanel>
        <ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
        </ajaxToolkit:TabPanel>
        </ajaxToolkit:TabContainer>             

       </ItemTemplate>
       </asp:TemplateField>
       </Columns>
      
        </asp:GridView>

MAke sure you have defined <asp:ScriptManager /> in ur page

AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the AjaxScriptManager in System.Web.Ajax.dll, or use the ToolkitScriptManager in AjaxControlToolkit.dll

Refer to: – http://forums.asp.net/p/1516859/3632563.aspx

Hi i have used tool script manager oustside the grid view.still iam getting the same error.tab container is working perfectly outside the grid view.But inside the gridview when i add tabpanel iam getting the same error

Hi, 

Please make sure you have included ToolkitScriptManager in the page. I have test on my side, tabcontainer in gridview is no problem.
Please check the code as follow:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="6"
            Height="1173px" Width="705px" DataSourceID="AccessDataSource1">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                    SortExpression="ID" />
                <asp:BoundField DataField="Content" HeaderText="Content" SortExpression="Content" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
                            <asp:TabPanel ID="TabbPnl1" runat="server">
                                <HeaderTemplate>
                                    View User Trace
                                </HeaderTemplate>
                                <ContentTemplate>
                                    <asp:Panel ID="pnlMain" runat="server">
                                        <asp:TextBox ID="txt" runat="server" Text="panel1"></asp:TextBox></asp:Panel>
                                </ContentTemplate>
                            </asp:TabPanel>
                            <asp:TabPanel ID="TabPanel1" runat="server">
                                <HeaderTemplate>
                                    View User Trace2
                                </HeaderTemplate>
                                <ContentTemplate>
                                    <asp:Panel ID="Panel1" runat="server">
                                        <asp:TextBox ID="TextBox1" runat="server" Text="panel2"></asp:TextBox>
                                    </asp:Panel>
                                </ContentTemplate>
                            </asp:TabPanel>
                        </asp:TabContainer>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Database1.accdb"
            SelectCommand="SELECT * FROM [Table1]"></asp:AccessDataSource>
    </div>
    </form>
</body>
</html>

Best wishes,

I have copy pasted the same code still iam getting the same error

Couldnot find any resources appropriate for the specified culture or the neutral culture.makesure "AjaxControlToolkit.propertied.resources.resources"was correctly embedde or linkined into assembly"AjaxControlToolkit"atcompile time,or that all the
satellite assemblies required are loadable and fully signed."

 

Error

Hi,

spriyanair

Couldnot find any resources appropriate for the specified culture or the neutral culture.makesure "AjaxControlToolkit.propertied.resources.resources"was correctly embedde or linkined into assembly"AjaxControlToolkit"atcompile time,or that all the satellite
assemblies required are loadable and fully signed."

I have tested again and find out that it will get the error above in design mode. However, the code works well when run it. In my opinion, it is a bug about VS. Thanks for your valuable feedback. You may also submit it to the following site in the formal
way:

http://connect.microsoft.com/VisualStudio/

Best wishes,

Thank you very much for your prompt reply.Its working well while run.I spend two weeks googling this…….:)

Hi, 

Very glad to help you and welcome to Asp.net forum again!

Best wishes,

[RESOLVED]Bind data through code behind to gridview

i am using this code to bind data to gridview in code behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim SqlDataSource1 As New SqlDataSource()
            SqlDataSource1.ID = "SqlDataSource1"
            Me.Page.Controls.Add(SqlDataSource1)
            SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("BaijuEPConnectionString").ConnectionString
            SqlDataSource1.SelectCommand = "SELECT Name,Company,Home,District,State from pers"
            GridView1.DataSource = SqlDataSource1
            GridView1.DataBind()
        End If
    End Sub

but it gives error as 

Keyword not supported: ‘provider’.

my data base is access and the connecting string is as under

  <add name="BaijuEPConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:webWing.mdb"
      providerName="System.Data.OleDb" />

Use AccessDataSource instead.

Sorry i didn’t exactly get that you are telling access database but you use sqldatasource. I am confused

check the following thread for this error

http://social.msdn.microsoft.com/Forums/vstudio/en-US/044bb47d-2209-4f78-a445-a1e67015c703/vbnet-beginners-error-keyword-not-supported-provider

See this article

Insert, update and delete in asp.net gridview step by step

Good thing is that, everything in this article is done from code behind.

Hi,

You are trying to read an Access database using a SQLDataSource object.

Try to replace it with  OleDbConnection.

Dim con As New OleDb.OleDbConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("BaijuEPConnectionString").ConnectionString
            con.Open()
            Dim da As New OleDb.OleDbDataAdapter("SELECT Name,Company,Home,District,State from pers", con)
            Dim dt As New DataTable
            da.Fill(dt)
            GridView1.DataSource = dt
            GridView1.DataBind()

Refer the below link

Accessing MDF File in .Net

try like this

        If Not IsPostBack Then
            Dim AccessDataSource1 As New AccessDataSource
            AccessDataSource1.ID = "AccessDataSource1"
            Me.Page.Controls.Add(AccessDataSource1)
            AccessDataSource1.DataFile = System.Configuration.ConfigurationManager.AppSettings("accessfile")
            AccessDataSource1.SelectCommand = "SELECT Name,Company,Home,District,State from pers"
            GridView1.DataSource = AccessDataSource1
            GridView1.DataBind()
        End If

web.config

<appSettings>
  <add key ="accessfile" value="C:webWing.mdb"/>
</appSettings>

[RESOLVED]Set Current date and add to database

I have an insertemplate and I can post the current date in the textbox that I need it to be in but when it inserts into the database there is nothing posted to the database.

<td><asp:TextBox Width="100" ID="SaleDate" runat="server" Text='<%# DateTime.Now.ToShortDateString() %>' /></td>

and here is the insert command:

InsertCommand="INSERT INTO [Sales] ( [EmployeeName], [SaleDate], [ContractNumber], [CustomerName], [Company], [SaleType], [SaleAmount], [Discount], [ExtendedPrice]) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)" 

and

<InsertParameters>
        <asp:Parameter Name="EmployeeName" Type="String" />
        <asp:Parameter Name="SaleDate" Type="String" />
        <asp:Parameter Name="ContractNumber" Type="String" />
        <asp:Parameter Name="CustomerName" Type="String" />
        <asp:Parameter Name="Company" Type="String" />
        <asp:Parameter Name="SaleType" Type="String" />
        <asp:Parameter Name="SaleAmount" Type="String" />
        <asp:Parameter Name="Discount" Type="String" />
        <asp:Parameter Name="ExtendedPrice" Type="String" />
    </InsertParameters>

You can set defaultvalue to today date in page load event

AccessDataSource1.InsertParameters("SaleDate").DefaultValue = Now.Date

Seem like you save the SaleDate as string, i sugest you to change the field type to DateTime

If you use string type, try this

AccessDataSource1.InsertParameters("SaleDate").DefaultValue = Now.Date.ToShortDateString

If you set Text=’<%# DateTime.Now.ToShortDateString() %>’ the value will not passed, usualy to pass value is using BIND() method. 

For easier way, use Access Date() function

InsertCommand="INSERT INTO [Sales] ( [EmployeeName], [SaleDate], [ContractNumber], [CustomerName], [Company], [SaleType], [SaleAmount], [Discount], [ExtendedPrice]) VALUES ( ?, Date(), ?, ?, ?, ?, ?, ?, ?)"

Then remove SaleDate parameter

<InsertParameters>
        <asp:Parameter Name="EmployeeName" Type="String" />
        <asp:Parameter Name="ContractNumber" Type="String" />
        <asp:Parameter Name="CustomerName" Type="String" />
        <asp:Parameter Name="Company" Type="String" />
        <asp:Parameter Name="SaleType" Type="String" />
        <asp:Parameter Name="SaleAmount" Type="String" />
        <asp:Parameter Name="Discount" Type="String" />
        <asp:Parameter Name="ExtendedPrice" Type="String" />
</InsertParameters>

I get an error with doing the page load. Says I can not use InserParameters as a method. What I am trying to accomplish is that most of the time the sale that is being entered is for the current day but I want the ability to change it. Any additional thoughts
or suggestions are greatly appreciated.

c#, try this

AccessDataSource1.InsertParameters["SaleDate"].DefaultValue = DateTime.Now.Date.ToString();

or

AccessDataSource1.InsertParameters["SaleDate"].DefaultValue = DateTime.Now.Date;

[RESOLVED]Generate INSERT UPDATE DELETE statement grey out

I have produced a database in access and am using visual web developer to display it. I have already used accessdatasource to add one table but when i try to add other tables i want to use the generate insert update delete option but it is ‘greyed out’.
All of my tables have primary keys so i know that this is not the problem, any help would be greatly appreciated. thanks

You can’t create INSERT etc statements across joins.  You need a record with a Primary Key in order to insert antoher record that’s related to it.  Access doesn’t support batch statements, so what you appear to be trying to do isn’t possible.

[RESOLVED]Access code

Here is a code. i want to use it with muy access database.

Private Sub BindGridData()
        Dim con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
        Dim cmd As New SqlCommand("select * from UserInformation", con)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet()
        da.Fill(ds)
        gvdetails.DataSource = ds
        gvdetails.DataBind()
    End Sub

i had set it as

<add name="baijuepConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:webAUTH.mdb"
      providerName="System.Data.OleDb" />

when i give the connection string as 

baijuepConnectionString
then it gives error as

Keyword not supported: ‘provider’.

Use app setting

<appSettings>
    <add key="baijuepConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:webAUTH.mdb"/>


  </appSettings>
Dim connstr As String = ConfigurationManager.AppSettings("baijuepConnectionString")

Baiju EP

i had set it as
<add name="baijuepConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:webAUTH.mdb"
      providerName="System.Data.OleDb" />

when i give the connection string as 

baijuepConnectionString
then it gives error as

Keyword not supported: ‘provider’.

You’re using the wrong NameSpace. Instead of the System.Data.SqlClient namespace, you need to use the System.Data.OleDb namespace:

 

Using con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:webAUTH.mdb")
  Using cmd As New System.Data.OleDb.OleDbCommand("select * from UserInformation", con)
   ‘……
  End Using
End Using

http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access