Setting Field To Integer From SqlDataAdapter
Apr 1, 2008
How do i get the result 'puzzle' from the SQL and assign it to Integer and use it to compare with Request.Form ?
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Dim connString As String = _ ConfigurationManager.ConnectionStrings("Local_LAConnectionString1").ConnectionString
Dim strsql As String = _
"Select CustomerID,CustomerNo,dbo.LA_DEC(Passkey) as passcode,dbo.LA_DEC(PuzzleKey) As puzzle, PuzzleFlag, NickName from Customers Where CustomerNo = '" & myAccount & "'"
Using myConnection As New SqlConnection(connString) Dim myCommand As New SqlCommand(strsql, myConnection)
myConnection.Open()
Dim PuzzleDataSet As New DataSet
Dim PuzzleAdapter As New SqlDataAdapter(myCommand) // <---- Coding here
myConnection.Close()
End Using
End Sub
View 7 Replies
ADVERTISEMENT
Sep 14, 2006
I have a table with an integer field (contains test values like 2, 7,8,9,12,..) that I want to convert to an Identity field. How can this be done in t-sql?
TIA,
Barkingdog
View 1 Replies
View Related
Oct 7, 2004
hi all,
i have an autonumber field (primary key) and another integer field as part of a table. What i want to do is when a record is created, the default value of the integer field should be the_autonumber+1000 for eg record with pk 82 will have an integer field that's automatically 1082. Would it be possible to do this ? Thanks in advance.
View 2 Replies
View Related
Aug 27, 2004
If I have a field where 99.9% of the time the answer is going to be "No", would I be better, in terms of disk space, using:
A bit field
OR
A tiny int field, with a NULL for the 99.9% that are "NO", and a 1 for those that are "YES".
I'm using SQL Server 7.0.
My application developer has no preference.
Thanks.
View 4 Replies
View Related
May 29, 2006
Hi everybody,
Could someone help me ???
Iam starting with sql
My problem ..
Ihave a table Table_customer
In this table a column Table_customer.no
This column contain 8000 rows.
with customer numbers: like 30789
I would like to modify once all this row adding just before the number
a value to all these rows.This value will be a 60
So will have instaed of 30789 a 6030789
This column is an integer.
I have try a simple select wich give me this result
How i can do this with update ?
probably i have to convert fisrt to caracters
select kunr,nov_kunr=
'30'+ltrim(str(kunr))
from event
where kunr is not null
Thank
View 3 Replies
View Related
Feb 17, 2007
I have a field ID of type integer, I want to put two numbers in that field: 3 and 7, so what I do is just store the number 37.Now, is there a command in SQL server which checks if the ID field contains a number I look for, say 7.Something like a CONTAINS keyword...If there is, could someone please tell me what it is AND tell me a bit more about it :memory usage, (dis)advantages etc.
View 1 Replies
View Related
Feb 4, 2004
I have an integer field that ranges from 3 to 6 numbers and I need to left pad leading zeros so the field is always a char(7). What is the syntax to do this? Thanks in advance.
0001234
0012345
0123456
1234567
View 1 Replies
View Related
Jan 28, 2008
Hello,
I am trying to write an SQL command to set the default value of an integer column I have within a table.
ALTER TABLE TableName alter column ColumnName int default 0
Any suggetions?
View 3 Replies
View Related
Oct 9, 2007
We have account numbers that are string values, looking like: "01.02.02.00.0040.000.000".
We need to parse individual segments and pull out a range of values treating the segment like an integer. For example we would like all accounts that have the fifth segment ranging in values from .0040. through .0060. inclusive.
We've been trying to do something with the like clause: LIKE '__.__.__.__.[0-0][0-0][4-6][0-0]'.
We want 40 through 60 but we're getting 40, 50, and 60. If we change the last bracket to [0-9] we get 40 through 69.
Does anyone have any suggestions as to either fix our like clause or another approach?
Thanks.
John
View 4 Replies
View Related
Sep 3, 2007
Hello,
what's best for year resp. quarter Field, char(4) resp. char(1), integer or other?
Both are part of a composite index.
Thanks
Silas
View 6 Replies
View Related
Sep 22, 2014
I am facing problem with re numbering of field records in a table.I am having one table with below records.
sid(identity/primarykey) stickyId(Integer) UserId(integer)
102 0 171
103 1 171
104 2 171
105 3 171
here how to renumbering stickyId values when deleted particular stickyId from UI. Here stickyId field is Integer type only. not primarykey/identity field.
View 3 Replies
View Related
Jul 2, 2007
I have the folliwing two fields, want tp concatenate:
=Fields!sequenceno.Value & =Fields!LogType.Value
Thank you very much for the information.
View 3 Replies
View Related
Nov 27, 2006
Currently I have the following stored procedure which simply adds a new row in my SQL Express 2005. What I want is that -1). before inserting the record find out the new ID (primary key) value. (ID is automatically a sequential integer generated by SQL Server)2). and set COMPANY_ID = (new) ID Any thoughts? Thanks ALTER PROCEDURE usp_tbl_Company_Insert @Company_ID int, @Name varchar(200), AS<FIND THE NEW ID of the new row in the database> @Company_ID = (new ID) INSERT INTO tbl_Company (Company_ID, Name,)VALUES (@Company_ID, @Name)
View 1 Replies
View Related
Jul 20, 2015
Working on a new database where the Date and Time are stored in a Date Time Field.
Then working on an OLDER database file within the same SQL Database contains these 2 items as integers:
transDate = "71615" (July 16, 2015)
transTime = "12345" (01:23:45 AM)
How do we convert both of them into a single SQL DateTime field such as "2015-07-16 01:23:45.000" so that it can be used in a join restricting to a date time in a different SQL File that properly has the DateTime in it?
This works well for converting the transDate Part in the select statement:
dbo.IntegerToDate(at.transDate) as transDate
* That returns: "2015-07-16 00:00:00.000"
* The resulting data must work directly in a Microsoft SQL Server Management Studio Query using either using the "on" statement or part of the "where" clause. In other words, NOT as a stored procedure!
Also must be able to be used as a date difference calculation when comparing the 2 files Within say + or - 5 seconds.
View 3 Replies
View Related
May 19, 2008
I'm selectively migrating a load of data from one database to another and would like to be able to get & set a table fields Description property (as seen on the Design window under Column Properties) programmatically. I'm having a spot of bother in actually finding how to do it - anyone know?
Ta,
Rob
P.S. Just thought I'd mention - I do know about sp_addextendedproperty, and while I will use that if I have to, it would be nice to be able to use the existing column property Description so that when editing, the user can see the value.
View 2 Replies
View Related
Mar 3, 2007
I am totally confused, i have set my data type in the ID field for my database as VarChar (SQL Server Database)
I am confused a have it declared in ASP.NET 2 as a string but it doesnt recognise it when i try and insert the data into a database, what am I doing wrong?
Thanks
1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
2
3 <script runat="server">
4
5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
6
7 End Sub
8
9 </script>
10
11 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
12 <span style="font-size: 11pt" id="SPAN1">
13 To initiate a new project, Enter details and
14 select <strong>Insert</strong>.
15 <br />
16 <br />
17 <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataSourceID="SqlDataSource1" Height="50px" Width="324px" DefaultMode="Insert">
18 <Fields>
19 <asp:BoundField DataField="ProjectID" HeaderText="ProjectID" SortExpression="ProjectID" />
20 <asp:BoundField DataField="ProjectName" HeaderText="Project Name" SortExpression="ProjectName" />
21 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
22 <asp:TemplateField HeaderText="Project Manager" SortExpression="ProjectManagersID">
23 <EditItemTemplate>
24 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProjectManagersID") %>'></asp:TextBox>
25 </EditItemTemplate>
26 <InsertItemTemplate>
27 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ProjMan" DataTextField="PMName"
28 DataValueField="ProjectManagersID" SelectedValue='<%# Bind("ProjectManagersID") %>'>
29 </asp:DropDownList><asp:SqlDataSource ID="ProjMan" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
30 DeleteCommand="DELETE FROM [ProjectManagers] WHERE [ProjectManagersID] = @ProjectManagersID"
31 InsertCommand="INSERT INTO [ProjectManagers] ([PMName]) VALUES (@PMName)" SelectCommand="SELECT [ProjectManagersID], [PMName] FROM [ProjectManagers]"
32 UpdateCommand="UPDATE [ProjectManagers] SET [PMName] = @PMName WHERE [ProjectManagersID] = @ProjectManagersID">
33 <DeleteParameters>
34 <asp:Parameter Name="ProjectManagersID" Type="Int32" />
35 </DeleteParameters>
36 <UpdateParameters>
37 <asp:Parameter Name="PMName" Type="String" />
38 <asp:Parameter Name="ProjectManagersID" Type="Int32" />
39 </UpdateParameters>
40 <InsertParameters>
41 <asp:Parameter Name="PMName" Type="String" />
42 </InsertParameters>
43 </asp:SqlDataSource>
44 </InsertItemTemplate>
45 <ItemTemplate>
46 <asp:Label ID="Label1" runat="server" Text='<%# Bind("ProjectManagersID") %>'></asp:Label>
47 </ItemTemplate>
48 </asp:TemplateField>
49 <asp:TemplateField HeaderText="Project Type" SortExpression="ProjectTypeID">
50 <EditItemTemplate>
51 <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ProjectTypeID") %>'></asp:TextBox>
52 </EditItemTemplate>
53 <InsertItemTemplate>
54 <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ProjType" DataTextField="ProjectType"
55 DataValueField="ProjectTypeID" SelectedValue='<%# Bind("ProjectTypeID") %>'>
56 </asp:DropDownList><asp:SqlDataSource ID="ProjType" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
57 DeleteCommand="DELETE FROM [ProjectType] WHERE [ProjectTypeID] = @ProjectTypeID"
58 InsertCommand="INSERT INTO [ProjectType] ([ProjectTypeID], [ProjectType]) VALUES (@ProjectTypeID, @ProjectType)"
59 SelectCommand="SELECT * FROM [ProjectType]" UpdateCommand="UPDATE [ProjectType] SET [ProjectType] = @ProjectType WHERE [ProjectTypeID] = @ProjectTypeID">
60 <DeleteParameters>
61 <asp:Parameter Name="ProjectTypeID" Type="Int32" />
62 </DeleteParameters>
63 <UpdateParameters>
64 <asp:Parameter Name="ProjectType" Type="String" />
65 <asp:Parameter Name="ProjectTypeID" Type="Int32" />
66 </UpdateParameters>
67 <InsertParameters>
68 <asp:Parameter Name="ProjectTypeID" Type="Int32" />
69 <asp:Parameter Name="ProjectType" Type="String" />
70 </InsertParameters>
71 </asp:SqlDataSource>
72 </InsertItemTemplate>
73 <ItemTemplate>
74 <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProjectTypeID") %>'></asp:Label>
75 </ItemTemplate>
76 </asp:TemplateField>
77 <asp:BoundField DataField="StatusID" HeaderText="Status" insertvisible=False readonly=True SortExpression="StatusID" />
78 <asp:CommandField ShowInsertButton="True" ButtonType=Button />
79 </Fields>
80 </asp:DetailsView>
81 <br />
82 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
83 DeleteCommand="DELETE FROM [Project] WHERE [ProjectID] = @ProjectID" InsertCommand="INSERT INTO [Project] ([ProjectName], [Description], [ProjectManagersID], [ProjectTypeID], [StatusID]) VALUES (@ProjectName, @Description, @ProjectManagersID, @ProjectTypeID, @StatusID)"
84 SelectCommand="SELECT [ProjectID], [ProjectName], [Description], [ProjectManagersID], [ProjectTypeID], [StatusID] FROM [Project]"
85 UpdateCommand="UPDATE [Project] SET [ProjectName] = @ProjectName, [Description] = @Description, [ProjectManagersID] = @ProjectManagersID, [ProjectTypeID] = @ProjectTypeID, [StatusID] = @StatusID WHERE [ProjectID] = @ProjectID">
86 <DeleteParameters>
87 <asp:Parameter Name="ProjectID" Type="Int32" />
88 </DeleteParameters>
89 <UpdateParameters>
90 <asp:Parameter Name="ProjectName" Type="String" />
91 <asp:Parameter Name="Description" Type="String" />
92 <asp:Parameter Name="ProjectManagersID" Type="Int32" />
93 <asp:Parameter Name="ProjectTypeID" Type="Int32" />
94 <asp:Parameter Name="StatusID" Type="Int32" />
95 <asp:Parameter Name="ProjectID" Type="Int32" />
96 </UpdateParameters>
97 <InsertParameters>
98 <asp:Parameter Name="ProjectID" Type="String" />
99 <asp:Parameter Name="ProjectName" Type="String" />
100 <asp:Parameter Name="Description" Type="String" />
101 <asp:Parameter Name="ProjectManagersID" Type="Int32" />
102 <asp:Parameter Name="ProjectTypeID" Type="Int32" />
103 <asp:Parameter Name="StatusID" Type="Int32" DefaultValue=1 />
104 </InsertParameters>
105 </asp:SqlDataSource>
106 </span>
107 </asp:Content>
108
109
View 1 Replies
View Related
Mar 2, 2005
Hello!
I am using a Ms-Access DS which is accessed by a website's server-side scripts.
What I would like to do is set an existing record's date/time field to null. I have tried to simply alter its value by not including any data within the sharps (##), however that did not work.
How can I accomplish this?
Thank you!
Dave
View 2 Replies
View Related
Oct 24, 2007
Hello,
I have a report which displays a customers invoice, in both the companys local currency, and the customers local currency.
The report language is "English (United Kingdom)"
The fields showing customers currency language setting is set to something else, i.e. "France (French)" to display the Euro currency.
The application handles 34 currencies, the query returns the language string, ("France (French)"), to allow the report to bind its language setting to the querys output.
However, it doesn't work, a normal textbox will display the correct country name string, but Reporting Services cannot bind the language setting to a query result. So I also tried setting it as a report parameter, but no joy either (all currencys revert to USD).
I'm using =First(Fields!curFormat.Value, "myDataSet") to bind the 'language' setting, the result of this expression returns "France (French)", which is a valid option for this language setting, as it's in the drop down list.
Rather than create 34 seperate reports for each currency, are there any suggestions on how to bind a fields language setting to a query result?
View 3 Replies
View Related
Sep 30, 2007
hi
it looks like my thread has been deleted but I keep on asking.
When trying to connect to a table i a SQL2005 database in a vb.Net webapplication I get the following error message from the wizard:
"The wizard detected the following errors when configuring the data adapter "SqlDataAdapter1".
"Check" Generated SELECT Statement
"Check" Generated Mappings
"Warning" Generated INSERT Statement
There were errors configuring the data adapter
"Warning" Generated UPDATE Statement
There were errors configuring the data adapter
"Warning" Generated DELETE Statement
There were errors configuring the data adapter"
The same connection works fine in a vb6 application. I have seen other threads concerning this in this forum but I can't find any answers. Any ideas anyone?
ciao chris
View 2 Replies
View Related
Aug 16, 2006
Hi guys. Does anybody have any clue about how to create a class which inherits from SqlDataAdapter? I tried but looks like SqlDataAdapter is not inheritable. I would like to extend it with some custom method such as a method which fills a Dataset (used with a DataGrid) with the only few records to display per page (say 20) against the thousand records it might instead contain otherwise.Any workarounds? Many thanks in advance for your help.
View 1 Replies
View Related
Mar 26, 2007
Hi I am writing an app in flash which needs to hook up to MS SQL via asp.I need the code below to pass the var (ptodaysDate) to the sql statement. I can hard code it in and it works great but I really need to pass the var from flash.Pulling my hair out here, not much left to go.Any help greatly appreciated.---------------------------------------------- [WebMethod] public Schedule[] getSchedule(int ptodaysDate) { SqlDataAdapter adpt = new SqlDataAdapter("SELECT scheduleID, roomName, eventType,unitName,groupName,staffName,staffName2,theDate,theEnd FROM tb_schedule Where theDate >= @rtodaysDate", connString); SqlParameter rtodaysDate = new SqlParameter("@rtodaysDate", ptodaysDate); DataSet ds = new DataSet(); ArrayList al = new ArrayList(); adpt.Fill(ds); foreach (DataRow row in ds.Tables[0].Rows) { Schedule obj = new Schedule(); obj.scheduleID = (int)row["scheduleID"]; obj.roomName = (string)row["roomName"]; obj.eventType = (string)row["eventType"]; obj.unitName = (string)row["unitName"]; obj.groupName = (string)row["groupName"]; obj.staffName = (string)row["staffName"]; obj.staffName2 = (string)row["staffName2"]; obj.theDate = (string)row["theDate"]; obj.theEnd = (string)row["theEnd"]; al.Add(obj); } Schedule[] outArray = (Schedule[])al.ToArray(typeof(Schedule)); return outArray; } public class Schedule { public int scheduleID; public string roomName; public string eventType; public string unitName; public string groupName; public string staffName; public string staffName2; public string theDate; public string theEnd; }
View 2 Replies
View Related
Apr 25, 2007
It's a pretty basic question but I haven't been able to find any examples out there. I dimmed a dataadapter and would like to reuse later in my code (line 3 in the code below). What is the correct syntax to do this? Dim da As New SqlDataAdapter("SELECT * FROM myTable", conn)da.Fill(myDataTable)da.______ ("SELECT * FROM myTable2", conn)da.Fill(myDataTable2)
View 2 Replies
View Related
Aug 15, 2007
I'm working on a project to dynamically create PDFs with content from an SQL server. My current approach is to get the data I need into a DataSet using SqlDataAdapter, write the DataSet to a stream as XML, transform the XML into FO and then output a pdf using FOP. For some reason I get the following exception "System.NullReferenceException - Object reference not set to an instance of an object" when I try to set the SelectCommand property of my data adapter. Code for the project follows:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim con As SqlConnection Dim cmd As SqlCommand Dim IDlist As String Dim keyidary As Array Dim query As String Dim tempxml As Stream query = "*****query is valid and very long, so it's not included here*****" IDlist = Request.Form("chosenIDs") keyidary = Split(IDlist, ",") Dim makequery As New StringBuilder(query) For Each ID As String In keyidary makequery.Append(" OR (KeyID = '" & ID & "')") Next query = makequery.ToString() 'Response.Write(query) When uncommented this prints the query just fine 'Response.End() Try con = New SqlConnection con.ConnectionString = "****Connection String is valid****" cmd = New SqlCommand cmd.CommandText = query cmd.CommandType = CommandType.Text cmd.Connection = con Dim adpt As SqlDataAdapter adpt.SelectCommand = cmd 'Response.Write(query) When these are above or between the previous 2 statements, query is printed, 'Response.End() otherwise I get the error described above. Dim profiles As New DataSet adpt.Fill(profiles) profiles.WriteXml(tempxml) Dim step1 As XslTransform = New XslTransform Dim step2 As XslTransform = New XslTransform step1.Load(Server.MapPath("TransAttmpt1.xslt")) step2.Load(Server.MapPath("formatXML.xsl")) Dim xml, pdf As String xml = "profiles.xml" pdf = "Profiles.pdf" Dim temp2xml As New XPathDocument(tempxml) Response.Write(query) Response.End() Dim midstream As Stream Dim finalxml As StreamWriter = New StreamWriter(xml) step1.Transform(temp2xml, Nothing, midstream, Nothing) Dim xpathdoc2 As XPathDocument = New XPathDocument(midstream) step2.Transform(xpathdoc2, Nothing, finalxml, Nothing) GeneratePDF(xml, pdf) 'There's a lot more but it doesn't seem relevant now.... I'm somewhat at a loss on how to proceed and any help is very greatly appreciated.Thanks!
View 2 Replies
View Related
Oct 1, 2007
Hi all,
I have datatable having around 50 rows and 3 columns ID, Name and ExpVal, which is an expression columns,where the values can be any SQL functions Like REPLICATE(), SOUNDEX ( 'value' ) Or REVERSE ( 'value' ).....
i want to insert each row in that datatable like
INSERT INTO TAB1 ( ID, Name, ExpVal) VALUES (1, 'some name', SOUNDEX ( 'some name' ) )
so that the ExpVal will have value of the function ie inserted row look like
ID Name ExpVal1 some name S500 <--- Result of SOUNDEX ( 'some name' )
I'm using sqldatadapter to insert these values to the database
string sql = "INSERT INTO TAB1 (ID, Name, ExpVal)VALUES (@ID, @Name, @ExpVal) ";SqlDataAdapter sqlAdptr = new SqlDataAdapter();SqlCommand sqlCmd = new SqlCommand(sql, con);sqlCmd.parameters.Add("@ID", SqlDbType.Int, 0, "ID");sqlCmd.parameters.Add("@Name", SqlDbType.NVarChar, 200, "Name");sqlCmd.parameters.Add("@ExpVal", SqlDbType.VarChar, 100, "ExpVal");sqlAdptr.InsertCommand = sqlCmd;sqlAdptr.Update(dataTable);
This works fine, but the problem is, now the TAB1 contains
ID Name ExpVal1 some name 'SOUNDEX ( 'some name' )' instead of S500
Thatis the sql funtion is passed by SqlDataAdapter to database as a string and it is not executing while row is inserted to the table.Please provide what changes i have to make if i want SOUNDEX ( 'some name' ) to executed while data insertion take place
Thanks in advance
View 1 Replies
View Related
Jun 3, 2008
I'm getting a strange error with my dataadapter. Here's my code: using (SqlConnection conn = new SqlConnection(
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
SqlDataAdapter da = new SqlDataAdapter("sprocCUSTOM", conn);
da.SelectCommand.Parameters.AddWithValue("@eventID", EventID);
conn.Open(); //open connection
DataSet ds = new DataSet();
da.Fill(ds);
gvAttendees.DataSource = ds;
gvAttendees.DataBind();
}This is the error I'm getting: Incorrect syntax near 'sprocCUSTOM'.But the error is highlighted at the line that reads "da.Fill(ds);"There's nothing wrong with the stored procedure either. It exists and works fine.
View 2 Replies
View Related
Feb 6, 2004
I am using SqlDataAdapter.Update(DataSet) to insert records into multiple tables in one call, but for some reason only first table was inserted.
Dim _cnn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim _sql As String = "Select a,b FROM Table1;Select d, c From Table2;"
Dim _da As New SqlDataAdapter(_sql, _cnn)
Dim _sqlCmdBdr As New SqlCommandBuilder(_da)
Dim _ds As New DataSet
_da.Fill(_ds)
Dim _newrow1 As DataRow = _ds.Tables(0).NewRow
_newrow1("a") = "NewA"
_newrow1("b") = "NewB"
_ds.Tables(0).Rows.Add(_newrow1)
Dim _newrow2 As DataRow = _ds.Tables(1).NewRow
_newrow2("d") = "NewD"
_newrow2("c") = "NewC"
_ds.Tables(1).Rows.Add(_newrow2)
_da.Update(_ds)
new record inserted only into Table1, no new rows in Table2
Please advise!
Thanks
View 1 Replies
View Related
Jul 6, 2007
Hi,
I am porting an ASP.NET/C# application from Microsoft Access to SQL Server 2005. In my code I have a method that uses the DataAdapter class to open a table, read some values out of it which are stored, open a second table, read some additional data from it storing the data in the same structure as used before, then updating the first table with the combined data.
When I execute the dataAdapter.Update() method I get the following error:
"Dynamic SQL generation for the Update Command is not supported against a Select Command that does not return any key column information."
I am uncertain what this error is about. This code worked fine against Microsoft Access so it must be something different in how SQL Server works.
Can anyone tell me what this error is complaining about?
Many thanks!
Bob
View 1 Replies
View Related
Mar 16, 2007
With MUCH help from this site and its users, I now know how to link a SqlCommand to a stored procedure:
What I don't know how to do, if it is possible, is to use a stored procedure with a SQLDataAdapter...
Here is the code as I am using, anyone have an idea on how to do this the right way?
' Define data objects
Dim conn As SqlConnection
Dim dataSet As New DataSet
Dim adapter As SqlDataAdapter
If ViewState("FooterDataSet") Is Nothing Then
' Read the connection string from Web.config
Dim connectionString As String = _
ConfigurationManager.ConnectionStrings( _
"Greensheet").ConnectionString
' Initialize connection
conn = New SqlConnection(connectionString)
' Create adapter
adapter = New SqlDataAdapter("SELECT * " & _
"FROM Table " & _
"WHERE (ID= " & intID & ")", conn)
' Fill the DataSet
adapter.Fill(dataSet, "Footer")
' Store the DataSet in view state
ViewState("FooterDataSet") = dataSet
Else
dataSet = ViewState("FooterDataSet")
End If
' Prepare the sort expression using the gridSortDirection and
' gridSortExpression properties
Dim sortExpression As String
If gridSortDirection = SortDirection.Ascending Then
sortExpression = gridSortExpression & " ASC"
Else
sortExpression = gridSortExpression & " DESC"
End If
' Sort the data
dataSet.Tables("Footer").DefaultView.Sort = sortExpression
' Bind the grid to the DataSet
footerGrid.DataSource = _
dataSet.Tables("Footer").DefaultView
footerGrid.DataBind()
View 1 Replies
View Related
Jul 13, 2007
Since my select command involves multiple tables, I manually write the insert command, proplating the SqlParameters as follows:
string insCmdText = "INSERT INTO itcac_alan.COURSE " + " ([COURSE_ID], [COURSE_NAME], [COURSE_NO], [BEGIN_DATE], [END_DATE], [CREATER]) " + " VALUES(@COURSE_ID, @COURSE_NAME, @COURSE_NO, @BEGIN_DATE, @END_DATE, @CREATER)";
SqlCommand insCmd = new SqlCommand(insCmdText, conn); insCmd.Parameters.Add("@COURSE_ID", SqlDbType.VarChar); insCmd.Parameters.Add("@COURSE_NAME", SqlDbType.VarChar); insCmd.Parameters.Add("@COURSE_NO", SqlDbType.VarChar); insCmd.Parameters.Add("@BEGIN_DATE", SqlDbType.DateTime); insCmd.Parameters.Add("@END_DATE", SqlDbType.DateTime); insCmd.Parameters.Add("@CREATER", SqlDbType.VarChar);
da.InsertCommand = insCmd; // da is a data adapter
However, as I use the preceding adapter to update the underlying database which in fact is based on a disconnected DataRow, an exception is thrown:
The parameterized query '(@COURSE_ID varchar(8000),@COURSE_NAME varchar(8000),@COURSE_NO ' expects the parameter '@COURSE_ID', which was not supplied.
The code I update the database is as follows:
DataRow newRow = sourceTable.NewRow(); //sourceTable is a DataTable whose data rows are populated with da (SqlDataAdpater) in the preceding code
// Populating the newRow
Hashtable newValues = new Hashtable();
.....................
foreach (DictionaryEntry entry in newValues) { // entry.Key is identical to a column name in the newRow newRow[(string)entry.Key] = (entry.Value == null ? DBNull.Value : entry.Value); }
sourceTable.Rows.Add(newRow);
adapter.SelectCommand.Connection.Open();
adapter.Update(sourceTable); // Exception is thrown here
adapter.SelectCommand.Connection.Close();
Please give me some directions to debug. It seems that the values of Columns withn DataRow cannot be fetched into the corresponding adapter.InsertCommand.Parameters by the adpater. (As I use SqlCommandBuilder to automatically generate insert command, the code above wroks rightly.)
Thanks a million.
Ricky.
View 2 Replies
View Related
Aug 14, 2007
I know there are loads of posts on this, but this just will not update. I have tried various forms of the code all to no avail. And now I'm ready to throw my PC out the window........
What am I doing wrong?
cheers Mike
Dim da As SqlDataAdapterDim dSetOrp As DataSet
oCn = New SqlConnection(db.m_ConnectionString)
oCn.Open()da = New SqlDataAdapter("Select * from contact WHERE conid = " & lngConId, oCn)
dSetOrp = New DataSet
da.Fill(dSetOrp, "locTable") ' Fill the DataSet.
dSetOrp.Tables(0).Rows(0)("ConSttDate") = dtEffDateDim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
myBuilder.GetUpdateCommand()
da.UpdateCommand = myBuilder.GetUpdateCommand()
lRows = da.Update(dSetOrp, "locTable")
View 2 Replies
View Related
Feb 7, 2008
MyCommand.Parameters.Add(new SqlParameter("@ConsultantName",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@Calls",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@PPC",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@Mth",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@DaysInMonth",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@Coach",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@Center",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@ProductValue",SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@ObjectiveValue",SqlDbType.VarChar));
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.CommandTimeout = 360;
try
{
SqlDataAdapter saveCenterCoaches = new SqlDataAdapter(MyCommand);
saveCenterCoaches.InsertCommand = MyCommand;
DataSet updateSet = finalSet.GetChanges(DataRowState.Added);
saveCenterCoaches.Update(updateSet.Tables[0]);
}
catch(Exception ex)
{
throw ex;
}
Iam getting "Procedure expects parameter @ConsultantName, which was not supplied."
I have consultantname and other parameters built in my datatable.
Is it the correct way of doing?
Can someone help.It is urgent.
View 5 Replies
View Related
Feb 20, 2008
Hi, I was looking at how to update a database using SqlDataAdapter and I stumbled upon this code snippet from (http://www.java2s.com/Code/CSharp/Database-ADO.net/UpdatedatabaseusingtheSqlDataAdapter.htm):using System;
using System.Data;
using System.Data.SqlClient;
class Class1{
static void Main(string[] args){
SqlConnection thisConnection = new SqlConnection("server=(local)\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT ID, FirstName FROM Employee", thisConnection);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "Employee");
Console.WriteLine("name before change: {0}", thisDataSet.Tables["Employee"].Rows[9]["FirstName"]);
thisDataSet.Tables["Employee"].Rows[1]["FirstName"] = "Inc";
thisAdapter.Update(thisDataSet, "Employee");
Console.WriteLine("name after change: {0}", thisDataSet.Tables["Employee"].Rows[9]["FirstName"]);
}
}I was just wondering, without iteration, how did the line "thisDataSet.Tables["Employee"].Rows[1]["FirstName"] = "Inc";" managed to know which row it is to update? I tried it on my own application and it worked fine.Any help to assist me in understanding this would be appreciated. Thanks
View 3 Replies
View Related
Apr 28, 2006
Hello Dears;
I have an SqlDataAdapter which contains may queries. One query contians 3 query parameters as follows:
SELECT SUM(Amount) AS TotalFROM BoxesWHERE EntryDate BETWEEN @date1 AND @date2 AND Area=@Area
the query cannot be ran unless the queries parameters were provided. I have to access this query in code to add the parameters from controls. Is it possible to access it or use sqlDataSource instead?
Thanks alot
View 2 Replies
View Related