.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Sql DataSource Help

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :ASP.Net

Hello Everybody

I have a problem when Im trying to leave a comment on the new post. I made a two tables one is for new post and one is for new comments.

New post table looks like : NewPostId-PrimaryKey, UserId, Subject, BodyPost and DatePost

New Comment table : NewCommentId-PrimaryKey, NewPostId, UserId, BodyComment, DateComment,

I have created a relation  Between a NewPost table(UserId) + Asp_User(UserId) and NewComment table(NewPostId) + NewPost table(NewPostId)

When a want to leave a new comment the error comes up as can not istert a null value into NewPostId in NewComment table.

How should looks a correct code bellow?? Or any ideas how could i sort it out ?? Thanks a lot

        MembershipUser currentUser = Membership.GetUser();

        Guid currentUserId = (Guid)currentUser.ProviderUserKey;


        string connectionString = ConfigurationManager.ConnectionStrings["PostConnectionString"].ConnectionString;

        string insertSql = "INSERT INTO NewComment(BodyComment, UserId, NewPostId) VALUES (@BodyComment, @UserId, @NewPostId)";

        using (SqlConnection myConnection = new S

View Complete Post

More Related Resource Links

Hide a repeater in ASP.NET C# if the DataSource contains no items?

I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:
In the (C#) code-behind I'm basically using LINQ to pull a listing of information from an XML document and bind that information to the first repeater.

Searching for the answer to this, it seems the method is to determine whether the data for the nested repeater is empty. If it is, then you set the visibility of the repeater to false.

Manually sorting and paging Gridview without using datasource control

Many a times while working with Gridview we want to work with the paging and sorting functionality without using any datasource control. Gridview is flexible enough to perform these tasks without the use of any datasource control and only a few lines of code.

Dynamic Data, Domain datasource, Poco and lookups


Mr. Edward,

Excuse my question but: it is necessary to involve in our projects something more than just Dynamic Data or should we make use of all other features available in VS2010 (which will make assume taht they had been left out of the Dynamic Data framework) like: wef, poco, azure, wcf, cloud, mvc, silverllight, ajax, odata, agile, workflow, etc.?

Sorry my ignorance, I'm just transcribing names as they come to my mind and of which I don't know anything about


Carlos Porras (El Salvador)

How to write SQL Datasource programatically in VB


Can someone pls help me to rewrite this programatically!


<asp:SqlDataSource ID="DS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [Products] WHERE ([ProductID] = @QSID)">
                    <asp:QueryStringParameter DefaultValue="" Name="QSID" QueryStringField="ID"
                        Type="Int32" />


Thank You in advance!


Configure Datasource using gridview problem


Hi i  have one asp.net textbox control..

and one dropdownlist inside gridview itemtemplate textbox..

what my problem..?

A Textbox36 has values some thing like this A1','A2','A3

i wirte this below query in sqldatasource1 and this sqldarasource1 is binded to gridview ItemTemplate Dropdownlist..

Select ItemName from Table1 where code in (@C)

Here @C im refering to Textbox36..

It show me the record if it has one value if its multiple like A1','A2','A3 it not showing/filtering ItemName data..

Whatz the probel?

Search for a string in my datasource dynamically


I am displaying an Rssfeed on my page by using XmlDataSource and Datalist controls.

I want the user to be able to limit the information that is returned to my datalist.  To do this I have a textbox on the form that allows the user to enter their search criteria.

I need to be able to dynamically create a query string utilizing the information that the user entered in the textbox.  I am also using a drop down list and allowing the user to select whether they want to search in the title, description, or all parts of the xml file.

I am having trouble figuring out how to reference the data contained in my textbox in my query string.  Where the query string says 'asp', I want to replace 'asp' with the content from my sSearch variable.  Can anyone tell me how to reference my variable in the query string???

string sSearch = txtSearch.Text;
        string SQuery = "";

        if (DropDownList2.SelectedIndex == 0)
            SQuery = "[contains(title), 'asp')]";

Using SqlDataSource as the Datasource to Accordion



The accordion does not renders. What am I missing? I want to use a parent child kind of accordion. Perhaps the child is not defined correctly, but I would like to see at list the seven tabs with the name of each organ system show up. The numbers of records for each organ system varies and I need a text box for each organ/tissue to be displayed, so I can insert in a findings table.

Here is what I have

new protected void Page_Load(object sender, EventArgs e)
            ModalPanel.Visible = false;
            ds1 = GetSqlOrganSystems();

protected SqlDataSource GetSqlOrganSystems()

         SqlDataSource dsL = new SqlDataSource();
            dsL.ID = "ds1";
            //#DataBinder.Eval(Container.DataItem,"Organ_System_ID" DataBinder.Ev

Access and Bind data wihtout using Datasource Control


i want to bind my gridview with a dataset with concept of caching (to minimize the database server trips). plz give me a best example to get and bind data to gridview (command line) . grid paging is also enabled so example code should be capable to rebind data at Gridview page change.  

Databind ListView datasource and joined tables


Hi all.

I am not expert in ASP so i would be appreciated for the help. Issue connected to Entity FW, ListView Control, its Datasource and type convertion.

I have the  following LINQ query :


RoutesEntities routesModel = new RoutesEntities();
LocalesEntities localesModel = new LocalesEntities();
ObjectQuery routesQuery = (ObjectQuery) from routes in routesModel.Routes
                                                    join locales in localesModel.Locales
                                                    on routes.LocaleID equals locales.LocaleID

SQL Insert Using DataSource


Hello, having trouble with this code:
Me.SqlDataSource1.InsertParameters("@term") = New Parameter("@term"

How do you Get value from datasource in page behind

 I have declared a Sqldatasource  bound to FormView. i wish to get a field value out  in the page behind and assign to a variable for further process, while display other bound field values in Formview?   Thanks    

SSIS OLEDB DataSource - Parameterized Query

Hi Team,We use SSI 2005 for one of our projects. We need to connect to the Oracle database and extract data. When we extract data from the source, we use the OLEDB Source and pass the SQL statement through an expression. We have a limitation of 4000 character when we use these expressions. To avoid this, we tried using parameterized queries as mentioned below:SELECT col1, col2, col3 ... col n FROM tab1 WHERE col1 > :PARAM1;When we try to assign the parameters, we end up getting an error as below."Parameters cannot be extracted from SQL Command. The provider might not help to parse parameter information from the command. In that case, use the "SQl Command from Variable" access mode, in which the entire SQL commands is stored in a variable"However, if use the SQL Server as a data source, I can assign the parameters. Could anybody let me know if this is a limitation from SSIS orif I am doing something wrong.Please suggest.ThanksAtukuri

WPF - Refreshing Datasource after collection changed

Hi All I have a a couple of business objects, a Market Position (like a holding in Microsoft say) and a Client Collection, which aside from a few other variables will hold in an ObservableCollection(Of FuturesSecurity) a collection of FuturesSecurities positions. Each Client is held in a ObservableCollection(Of Client) and I happily have many clients in this collection. Each Object (Client and FuturesSecurity) both implement INotifyPropertyChanged and I can trace changes in prices right up to the user interface level (proof of life been a msgbox called at that level), however I cannot get this to be reflected in my databinding. Is there a way I can get this to refresh automatically? Shouldnt that be happening with Databinding anyway when the datasource changes? I am currently setting the data source as:     Me.DataContext = Clients Does anyone have anythoughts here? Happy to post more code as neccersary thanks in advance Chris

ComboBox Display list does not update if a datasource is a boxed string

I have a combo box databound to a BindingSource bound to a List<Holder> it has Holder.Name as its display value. I also have a text box bound to Holder.Name but if I change the text in the text box it will not change what is displayed in the combo box. Changing selected items and changing back will show the updated text in the text box but will still have the old value displayed in the combo box. How do I make the item in the combo box update? namespace Sandbox_Form { public partial class Form1 : Form { public Form1() { InitializeComponent(); lstBroken = new List<Holder>(); lstBroken.Add(new Holder("test1")); lstBroken.Add(new Holder("test2")); bsBroken = new BindingSource(lstBroken, null); cmbBroken.DataSource = bsBroken; cmbBroken.DisplayMember = "Name"; txtBroken.DataBindings.Add("Text", bsBroken, "Name"); lstWorks = new List<string>(); lstWorks.Add("test3"); lstWorks.Add("test4"); bsWorks = new BindingSource(lstWorks, null); cmbWorks.DataSource = bsWorks; txtWorks.DataBindings.Add("Text", bsWorks, null); } } public class Holder { public Holder(string name) { Name = name; } public string Name { get; set; } } }

How to bind a calendar control to a datasource

In my application, user will enter some meeting dates in one page.   In the details page, they need to see those dates to make a selection for one file number. I want to show a calendar in the details page whice will show the dates already entered. To do that I need to bind the calendar to a datasource to get the information from the database. Please guide me to do that. Thanks in advance,

Subscriptions using Windows Integrated Security (Datasource)

Hi All, Having an issue with SSRS 2008 at the moment, trying to setup subscriptions.Our system is configured so that any one of 10 users can login to the SSRS website using their windows domain account, and then launch report builder to design and save reports.  This all works very well, however, they have a problem when trying to setup subscriptions - the famous "Subscriptions cannot be created because the credentials used to run the report are not stored....."What the message says is true - the credentials are not stored as they are supplied by the user when they login to report builder.Is the /any/ workaround at all that doesn't involve storing the credentials?  It seems totally crazy that they cannot be prompted for them when setting up the subscription.  For this application its 100% essential to make the user provide their credentials when running reports, because they each see a filtered subset of the data in the report model (this is controlled DB side depeding on the login account), so their domain account needs to be passed to SQL server to enable this filtering to work.  If we saved their credentials then they would see all the data..and thats nasty.The only workaround I can come up with would be to create  a separate datasource for each user and upload a separate model, but thats really nasty to be honest and creates an ad

How do you change the datasource for a list based on another? ie a secondary list being a filtered

I'm actually using Sharepoint 2007, but am hoping this forum will help.  We want to be able to create a list based on a filtered view of another list.  I can create a Filtered List in Designer, but evidently this is saved as a query object on the server and not as another list that can be selected when using the basic Sharepoint tools.  In other words, it's only visible when in Designer.  This means that in order to use this for say a lookup column in another list object, I have to modify the datasource tags for the EditForm and NewForm.aspx pages within Designer.  Also, it means that adding a column would constantly require use of Designer.  We need this to be simple as not all those tasked with administrating pages will know how to do this.  I thought it would be easier if I could simply source a secondary list with the filtered list I created in designer.  In other words, make a secondary list source be that of a queried view of a master list.  Then this list could be used with all the simple tools provided.  Is this possible?  If so... how?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend