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


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

Insert values into a datatable.

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :Windows Application
 

Hi,

I have a datatable with 5 columns. Then i added another column "date" to this datatable.

I want to insert value  in every row for this column in this datatable.

When i use the following i am getting  Error-- ---- Conversion from type 'DataRow' to type 'Integer' is not valid.

How can i insert values into a datatable?

Thanks

 

 Public Sub insertBrktoDB()

    Dim mydt As New DataTable
    mydt = BreaksCSV()
    Dim dt As DataColumn = New DataColumn("Date")
    dt.DataType = System.Type.GetType("System.DateTime")
    mydt.Columns.Add(dt) '--------------p_date is a property which has the value to be inserted
    p_date = ds_rte.Tables("sched").Rows(1).Item("mdate").ToString
    For 
                                     
                                            
                                        

View Complete Post


More Related Resource Links

hsdsd: how to insert two values from text box1 to gridview g

  

database:a

table a

a                                 b

jhgd                           kljhskjd

sdghdshgd                 jkhdjhdjk

what i need is when enter some values(varchar ) in txt 1 and 2

it should be added in database and shown in gridview1 after i press butt1

 

any bodyknows full code answer/akdj


How to insert values into my table the data is coming from inline table valued function

  
Hi all,   i have table oi want insert values into my table the data is coming from inline table valued function how i can use the inline table valued function to insert datainto my table i have inline function which out puts 3 collumns of data how i can insert this data into my table i have the insert statment like below insert into tablename(c1,c2,c3,c4,c5) select ('abc',....................,'xyz') how i can use the out put put of my inline function to  to insert data into my columns c2,c3,c4. please help me out Thanks & Regards Sunil Yoganna

DataTable - How to get max and min values

  
Hi all, I have constructed a DataTable in the following way ---  DataTable projectedCPMdt = new DataTable();         projectedCPMdt.Columns.Add("ProjectedCPM", typeof(string));         projectedCPMdt.Columns.Add("0%", typeof(int));         projectedCPMdt.Columns.Add("1%", typeof(int));         projectedCPMdt.Columns.Add("2%", typeof(int));              projectedCPMdt.Rows.Add("70%", 1, 2, 3);         projectedCPMdt.Rows.Add("80%", 4, 5, 6);  DataTable projectedCPMdt = new DataTable();        projectedCPMdt.Columns.Add("ProjectedCPM", typeof(string));        projectedCPMdt.Columns.Add("0%", typeof(int));        projectedCPMdt.Columns.Add("1%", typeof(int));        projectedCPMdt.Columns.Add("2%", typeof(int));        projectedCPMdt.Rows.Add("70%", 1, 2, 3);        projectedCPMdt.Rows.Add("80%", 4, 5, 6);Its like a grid of values. And I need to select the max and min. In this case max = 6 and min =1.Can someone tlel me how to e

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

insert mulitple comma seperated values in a temp table

  
I have a reporting services report with a single parameter that can take up to 10 numbers which are comma delimited. I need to insert those numbers into a temp table with one column. So if the numbers were 1 - 10 I would expect to see something like this if querying the temp table Acct_Num 1 2 3 4 5 6 7 8 9 10 Is there a way to do this insert into the table using a comma delimeted string of numbers? ThanksFJK

Linq to SQL insert to datatable

  

I got the following query to group the table. I am wondering how to add a subtotal record with anonymous type.

string prevOriginator = string.Empty;
var oOriginator = (from I in dtIssue.AsEnumerable()
                            group I by new {RaisedBy = I.Field<string>("RaisedBy"), ItemType = I.Field<string>("ItemType")} into grp
                            orderby grp.Key
                            select new {RecType = "D",  RaisedBy = grp.Key.RaisedBy, ItemType = grp.Key.ItemType, Count = grp.Count() });
foreach (var record in oOriginator)
{
    if (record.RaisedBy != prevOriginator)
    {
        if (prevOriginator != string.Empty)
        {
             //add a subtotal record
  

Insert checkboxlist selected values into sql table using createuser wizard

  

Hi,

I am using CreateUserWizard control where I collect personal information from the user on the first step (ie. name, address, tel, mobile etc) then on the second step I collect information for membership service (ie. user name, password, email etc). When user clicks Create button, information is sent to two different tables in the same database. Everything works fine but one.

In the first step where I collect personal information, I also collect details about Interest which is a CheckBoxList (CheckBoxList is getting values from Interests table: 1-White, 2-Green, 3-Brown, 4-Maroon, 5-Yellow).

What I want to do is, when client selects his itnerest categories and clicks Create button, to send selected values from CheckBoxList into the third table called Categories. I want values to be registered into the CatCode column in Interests table as comma delimited. For example: if client selected "White", "Green" and "Yellow", appropriate values for those interests (such as 1, 3, 5) to be registered under Categories table CatCode column (like: 1,3,5).

Following is my code:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
        oncreateduser="CreateU

Validating form values before insert

  

Before committing the record from the postback of the Create or Edit method in my controller, I validate the values in the form against some business rules in the GetRuleViloations() of this domain object.  The following rule example is written in two ways.  The 1st one validates against the numeric values in form, the 2nd one validates using the associated object (lookup table in database) description via the foreign key.  I would like to use the 2nd method, but during the Create postback the associated object is always null.  

/***** this works for Edit postback but doesn't work for Create postback *****/
if (Reason.HasValue && (Status.HasValue && Status1.Status1.Contains("TBD"

Deleted Values Insert into a New Table

  
Hi All,

I have Database DB and Table CB ..CB has 3  dependent Tables OB ,CP,CI
So My Requirement is ..

delete  From CB
where ID_NUM not Like '99%'

But here delete will  not work because of FK .. so i need to delete records from OB CP CI Tables first ...and I need to store all the Deleted Records of all the 4 Tables (CB,OB,CP,CI) in a seperate Table
May be all 4 deleted values in a Table
or
each table deleted records in each Seperate newly created table..



all i Know to go each child table and delete but ....It may be time Running Script ...
Or
Individuall for Each delete and Store in new table



Can any one Help me on This .....


How to INSERT new row values from two different sources, all fields from a table plus one additional

  
--Loading the single row returned by a table valued function into a temp table works fine like this:
DECLARE @techNumLoop VARCHAR(25)

DECLARE @myTemp TABLE (
 Names Varchar(25)
,Item_Count Integer
,Expense_AP MONEY
--,[...20 more fields]
)
--Loop a while
INSERT @myTemp SELECT * FROM ufn_FindSomeRow(@techNumLoop)
--And finally display a table with one row for each function call
SELECT * FROM @myTemp
============
--My Question: what if I would like to also display the value of @techNumLoop passed in to ufn_FindSomeRow?
--Then I add a field to @myTemp to hold it:
DECLARE @myTemp TABLE (
 TechNum VARCHAR(25)--added

Trying to Retain Values in a FormView When Validations fails or the SQL Fails on an Insert

  

To me this should be much easier, but I can't seem to retain the values that are put in the Insert template upon a validation failure or when the sql fails. This will prevent the user from having to retype everything agin in the event of a failure.

As you can see I am using the Sub Insert_Click and not using an insert through the wizard. so the fields are unbound textboxes on the form. There are 2 dropdowns that provide choices for the other fields.

Any help would be appreciated. I pasted in the code using the text only option becuase the format was getting messed up. I porboably need more background on why the fields are blanking out.

 

 

See Code below

 

 

Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

' Dim sqlparm As String

Dim con As Data.SqlClient.SqlConnection = Nothing

Dim cmd As Data.SqlClient.SqlCommand = Nothing

Dim dr As Data.SqlClient.SqlDataReader = Nothing

Dim sql As String = ""

Dim x As Integer

' Dim x As Integer

'Validation

Try

If CType(Me.fvwAppSecurityDetails.FindControl("CorpIDTextBox"), TextBox).Text = "" Then

Me.lblMessage.Text = "CorpID cannot be blank"

Exit Try

Else : Page.Session("CorpID&

display / insert values by comparing 2 columns of a table

  

hi

i have a table which has the following columns 

A_ID, A_Value,A_Date,B_ID,B_Value_B_Date

 

i have another table as follows

A_ID,B_ID,A_Value,B_Value, Date

 

this is to be done 

* if A_date and B date are equal, one record shoould be entered to the TABLE 02. the values should be A_ID,B_ID,A_Value_B_Value and A_Date (since the date is equal, no problem; even can insert B_Date instead of A_Date)

* if A_Date and B_Date are different, then the following should happen

insert one record to TABLE02 as A_ID,B_ID, A_Value, 0 , A_Date

insert another record to TABLE02 as A_ID,B_ID, 0 , B_Value, B_Date

 

(As you can see, when the date differs we enter the single record of Table 01 into 2 recoerds in table 02. the Value column and Date column are related in such a way that when A's date is entered, the value for B should be 0 and vise versa..)

 

i tried having a UDF but in halfway remembered that we cannot include INSERTS in UDFs..

can anyone please explain me how can i solve this problem ??

 

PS: For your reference , i've sketched a diagram. please click on this link to view it for further clarifications

http://i54.tinypic.com/eq6p7t.png

 

thanks in advance

-novicedba :)


Carrying on DropDownList selected (values/indexes ) among "Insert" operations of the same kind

  

I have struggled trying to find a way of making current values selected from all dropdownlist that I might have available inside an Insert page [for any table that I could be working on]... [of course the amount of dropdownlist boxes displayed vary with each table depending on the database schema and referential integrity].

Could be possible that anyone had developed an standard control or a piece of code that can do this as to "carry on" previously dropdownlist selected values so they can be used again and make the UI more friendly because as it is now Dynamic Data resets all values and takes you back every single time you make an Insert operation? I guess Microsoft's Dynamic Data Team working on it ... shouldn't they?

Suppose that you are working entering data for a "products" catalog and you have to introduce 20 items of the same kind. You wouldn't be supposed to be selecting values from the same dropdownlists 20 different times if you had available previously selected values which will make your job easier.

I have tried successfully building a matrix which accomplishes this but I have faced the problem that when it comes to "composite keys" my solution doesn't work because I should have available the SelectedIndex instead of the SelectedValue that Dynamic Data uses by

DetailsView Get Values on Insert. Major Problem :(

  

Hellow!


I'm having a problem to get the inserted values from the detailsview. I've tried the following things:


           // Get Value from DropDown
        int TopicID = 0;
        foreach (DetailsViewRow row in ItemsDetailsView.Rows)
        {
            if (row.Cells[0].Text == "Topic")
            {
                 DropDownList TopicDropDown = (DropDownList)row.Cells[1].FindControl("Topic_TopicIDList");
                 TopicID = int.Parse(TopicDropDown.SelectedValue.ToString());
            }


        }

            MsgBox(CType(DetailsView1.Rows(1).Cells(0).Controls(0), Label))




            For Each row As DetailsViewRow In DetailsView1.Rows

                Dim cell1 As TableCell = row.Cells(1)

                Dim value1 As String

                value1 = cell1.Text

                MsgBox(value1)


            Next

            Dim item As New DetailsViewItem(col.ColumnName, row(index).ToString(), col.DataType.ToString(), col.DefaultValue)
          MsgBox(DetailsView1.Rows(1).Controls(0).)


            MsgBox([Enum].GetValues)







            tb = DetailsView1.FindControl("Categorie")
            s = tb.Text

            MsgBox(s.ToString)

            For Each dvr As DetailsViewRow In DetailsView1.Rows
                If dvr.Cells.Count = 2 Th

how to store the datatable values into the 1-D array

  

hi all ,

how to store the datatable values into the 1-D array , i know in for loop ... other than that is there means let me know please


Loosing Values in Form on Insert Attempt

  

 I have a page with an asp:FormView.  When I attempt an insert and it fails I loose the data in the form.  ViewState is enabled.

<asp:FormView ID="frm_Person" runat="server" DataKeyNames="Person" DataSourceID="ds_edit_Person" DefaultMode="Insert" ViewStateMode="Enabled"> 

I am trapping the error on the datasource with 

<asp:SqlDataSource ID="ds_edit_Person"....

oninserted="ds_Edit_Person_Sql_Event" onupdated="ds_Edit_Person_Sql_Event" ... 

(ErrorHandler is just a static lookup function):

protected void ds_Edit_Person_Sql_Event(object sender, SqlDataSourceStatusEventArgs e) {
        if (e.Exception != null) {
            SqlException sqlex = (SqlException)e.Exception;
            lbl_Error.Text = ErrorHandler.TranslateError(sqlex.Number);
            e.ExceptionHandled = true;
        }
        else {
            lbl_Error.Text = ErrorHandler.TranslateEr

Categories: 
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