SELECT query with querystring parameters using NULL value - asp.net

Hello to all respected members,
Presently I using following SELECT command in asp.net for populating a Gridview based on Query string values:
SelectCommand="SELECT ID, Date, Train, I_R, Dir_Ind, Detn, Rly, DiV, Loco, Shed, locoClass, loco_type FROM PunctualityMain WHERE Date >= #strdt AND Date <= #enddt AND ([Rly] = #rly OR #rly IS NULL) AND ([shed] = #shed OR #shed IS NULL) Order by Date ASC">
<SelectParameters>
<asp:QueryStringParameter Name="strdt" QueryStringField="strdt" Type="DateTime" />
<asp:QueryStringParameter Name="enddt" QueryStringField="enddt" Type="DateTime" />
<asp:QueryStringParameter Name="rly" QueryStringField="rly" Type="string" />
<asp:QueryStringParameter Name="shed" QueryStringField="shed" Type="string" />
</SelectParameters>
It is working fine also with two values null as :
http://elocos.railnet.gov.in/Punctuality/Punctualitydetail.aspx?strdt=5/1/2013&enddt=5/14/2013&rly=&shed=
Now I want to use same for Gridview with Delete, Insert & Update Commands which is as under:
DeleteCommand="DELETE FROM [PunctualityMain] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [PunctualityMain] ([Date], [Train], [Dir_Ind], [Detn], [Rly], [DiV], [Loco], [Shed], [locoClass], [loco_type]) VALUES (#Date, #Train, #Dir_Ind, #Detn, #Rly, #DiV, #Loco, #Shed, #locoClass, #loco_type)"
SelectCommand="SELECT * FROM [PunctualityMain] WHERE (([Date] >= #strdt) AND ([Date] <= #enddt) AND ([Shed] = #shed OR #shed IS NULL) AND ([Rly] = #rly OR #rly IS NULL)) ORDER BY [Date]"
UpdateCommand="UPDATE [PunctualityMain] SET [Date] = #Date, [Train] = #Train, [Dir_Ind] = #Dir_Ind, [Detn] = #Detn, [Rly] = #Rly, [DiV] = #DiV, [Loco] = #Loco, [Shed] = #Shed, [locoClass] = #locoClass, [loco_type] = #loco_type WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Date" Type="DateTime" />
<asp:Parameter Name="Train" Type="Int32" />
<asp:Parameter Name="Dir_Ind" Type="String" />
<asp:Parameter Name="Detn" Type="Int32" />
<asp:Parameter Name="Rly" Type="String" />
<asp:Parameter Name="DiV" Type="String" />
<asp:Parameter Name="Loco" Type="String" />
<asp:Parameter Name="Shed" Type="String" />
<asp:Parameter Name="locoClass" Type="String" />
<asp:Parameter Name="loco_type" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="strdt" QueryStringField="strdt" Type="DateTime" />
<asp:QueryStringParameter Name="enddt" QueryStringField="enddt" Type="DateTime" />
<asp:QueryStringParameter Name="rly" QueryStringField="rly" Type="string" />
<asp:QueryStringParameter Name="shed" QueryStringField="shed" Type="string" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Date" Type="DateTime" />
<asp:Parameter Name="Train" Type="Int32" />
<asp:Parameter Name="Dir_Ind" Type="String" />
<asp:Parameter Name="Detn" Type="Int32" />
<asp:Parameter Name="Rly" Type="String" />
<asp:Parameter Name="DiV" Type="String" />
<asp:Parameter Name="Loco" Type="String" />
<asp:Parameter Name="Shed" Type="String" />
<asp:Parameter Name="locoClass" Type="String" />
<asp:Parameter Name="loco_type" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
Why the above SELECT command not working with NULL values for rly & shed? However, with all the four query string values it is working like this
http://elocos.railnet.gov.in/Punctuality/Punctualitydetail.aspx?strdt=5/1/2013&enddt=5/14/2013&rly=CR&shed=KYN
Please suggest any solution for the problem so that it can work with this string also (NULL string values)
http://elocos.railnet.gov.in/Punctuality/Punctualitydetail.aspx?strdt=5/1/2013&enddt=5/14/2013&rly=&shed=

Because you get Empty value from empty querystring value =/= null
In order to get this working you should set null value manually.
I can suggest you at least 2 ways:
1) In codebehind:
string rly = Request.QueryString["rly"];
if (rly == "")
rly = null;
And then use it.
2) In SQL command:
Rly=NullIf('#rly','')
But I'm not sure if 2nd one will work like this, if it won't then you can try to workaround it like:
codebehind string empt = "";
SQL command Rly=NullIf('#rly','+empt+')
Or you can go some other way, the point is to verify it "rly" query is "", if it is then set it to null, otherwise leave it alone.

Related

How to configure SqlDataSource to handle a return value from Stored Procedure

I have a listview and in the listview Update commmand I am attempting to set the parameters defined in my SqlDataSource UpdateParameters property. When Update command fires, I recieve an error message stating
Procedure or function 'MyStoredProcedure' expects parameter '#ReturnResult', which was not supplied.
Here's the aspx with the SQL DataSource:
<asp:SqlDataSource ID="sqlDataForCustomers" runat="server"
ConnectionString="<%$ ConnectionStrings:GS_ConnectionString %>"
CancelSelectOnNullParameter="False"
SelectCommand="usp_WDE_Get_DG"
SelectCommandType="StoredProcedure"
UpdateCommand="usp_WDE_Save"
UpdateCommandType="StoredProcedure" >
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="GID" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="Order" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="PID" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PID" Type="Int32" />
<asp:Parameter Name="ProID" Type="Int32" />
<asp:Parameter Name="GID" Type="Int32" />
<asp:Parameter Name="DGapID" Type="Int32" />
<asp:Parameter Name="DEntryID" Type="Int32" />
<asp:Parameter Name="DEntrySetID" Type="Int32" />
<asp:Parameter Name="DEntryResult" Type="String" Size="250"/>
<asp:Parameter Name="DEServiceDate" Type="DateTime" />
<asp:Parameter Name="UserLoginID" Type="String" Size="50"/>
<asp:Parameter Name="UserPersonID" Type="Int32" />
<asp:Parameter Name="ServiceDate" Type="DateTime" />
<asp:Parameter Name="DGRowId" Type="Int32" />
<asp:Parameter Name="SRowId" Type="Int32" />
<asp:Parameter Direction="ReturnValue" Name="RetResult" Type="Boolean" DefaultValue="True" />
<asp:Parameter Direction="ReturnValue" Name="RetMsg" Type="String" Size="50" DefaultValue=""/>
</UpdateParameters>
Here is the ItemUpdating event of the LV in the code behind:
Sub CustomersGroupedByDataField_ItemUpdating(ByVal sender As Object, ByVal e As ListViewUpdateEventArgs) Handles CustomersGroupedByDataField.ItemUpdating
Dim rowValue As Integer = e.ItemIndex
Dim DataGapTypeBeingUpdated As String = CustomersGroupedByDataField.DataKeys.Item(rowValue).Value.ToString()
Dim boolTest As Boolean
boolTest = True
GetRowValues(DataGapTypeBeingUpdated)
CheckOOS()
sqlDataForCustomers.UpdateParameters("PID").DefaultValue = intPID.Value
sqlDataForCustomers.UpdateParameters("ProID").DefaultValue = intProID.Value
sqlDataForCustomers.UpdateParameters("GID").DefaultValue = intGID.Value
sqlDataForCustomers.UpdateParameters("DGapID").DefaultValue = intDGapID.Value
sqlDataForCustomers.UpdateParameters("DEntryID").DefaultValue = intDEntryID.Value
sqlDataForCustomers.UpdateParameters("DEntrySetID").DefaultValue = intDEntrySetID.Value
sqlDataForCustomers.UpdateParameters("DEntryResult").DefaultValue = strDEntryResultValue
sqlDataForCustomers.UpdateParameters("DEServiceDate").DefaultValue = CDate(dtServiceDate.Text)
sqlDataForCustomers.UpdateParameters("UserLoginID").DefaultValue = Convert.ToString(Session("LoginID"))
sqlDataForCustomers.UpdateParameters("UserPersonID").DefaultValue = Convert.ToString(Session("PersonID"))
sqlDataForCustomers.UpdateParameters("ServiceDate").DefaultValue = CDate(dtServiceDate.Text)
sqlDataForCustomers.UpdateParameters("DGRowID").DefaultValue = intDGapRowID.Value
sqlDataForCustomers.UpdateParameters("SRowID").DefaultValue = intSRowID.Value
End Sub
I'm at a loss as to how I should specify the return value as a parameter?
How to handle the Return value (RetResult & RetMsg)?
Thanks for looking,
There is a direction attribute of select parameters that marks an input parameter as a reference parameter. The same property is accessible in your code.
<SelectParameters>
<asp:Parameter Direction="ReturnValue" Name="MyReturnParameter" Type="Int32" />
</SelectParameters>
After the command executes you can retrieve the value using parameter.Value or bind it to a ui element.
I think you can find your solution here,
https://forums.asp.net/t/1049910.aspx?How+to+get+return+value+or+output+value+from+stored+procedure+with+sqldatasource+control+
In order to get the return value you need to declare a return paramater in sqldatasource... something like this
<InsertParameters>
Your Parameters
<asp:Parameter Direction="ReturnValue" Type="Int16" Name="ReturnValue" />
</InsertParameters>
Then you need to override sqldatasource's Inserted event like this ( here you can get the return value)
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
Response.Write(e.Command.Paramaters["ReturnValue"].Value);
}

Compiler Error Message: CS0029: Cannot implicitly convert type 'decimal' to 'string'

I use GridView and from this i want to insert update. I have done my job but when i use RchPaidAmt field with numeric data type the following message show:
Compiler Error Message: CS0029: Cannot implicitly convert type 'decimal' to 'string'
Data Type
RchID int
RchAppID int
RchCallDate datetime
RchComments varchar(150)
RchAttemptCall int
RchReceivedParty varchar(50)
RchPrmTaken int
RchCNPrm int
RchNxtPrmDate datetime
RchPaidAmt numeric(18, 2)
<UpdateParameters>
<asp:Parameter Name="RchAppID" Type="Int32" />
<asp:Parameter Name="RchCallDate" Type="DateTime" />
<asp:Parameter Name="RchComments" Type="String" />
<asp:Parameter Name="RchAttemptCall" Type="Int32" />
<asp:Parameter Name="RchReceivedParty" Type="String" />
<asp:Parameter Name="RchPrmTaken" Type="Int32" />
<asp:Parameter Name="RchCNPrm" Type="Int32" />
<asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
<asp:Parameter Name="RchPaidAmt" Type="Decimal" />
</UpdateParameters>
protected void GVCallHistory_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
string strRchAppID = hfRchAppID.Value;
string strRchCallDate = DateTime.Parse(Convert.ToString(DateTime.Now)).ToString("dd MMM yyyy HH:MM");
string strRchComments = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchComments") as TextBox).Text;
string strRchAttemptCall = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchAttemptCall") as TextBox).Text;
string strRchReceivedParty = ((e.CommandSource as Button).NamingContainer.FindControl("DDLRchReceivedParty") as DropDownList).SelectedValue;
string strRchPrmTaken = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchPrmTaken") as TextBox).Text;
string strRchCNPrm = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchCNPrm") as TextBox).Text;
string strRchNxtPrmDate = "";
if (Convert.ToString(((e.CommandSource as Button).NamingContainer.FindControl("txtRchNxtPrmDate") as TextBox).Text) !="")
{
strRchNxtPrmDate = DateTime.Parse(Convert.ToString(((e.CommandSource as Button).NamingContainer.FindControl("txtRchNxtPrmDate") as TextBox).Text)).ToString("dd MMM yyyy");
}
else
{
strRchNxtPrmDate = "01Jan1900";
}
**string strRchPaidAmt = ((e.CommandSource as Button).NamingContainer.FindControl("txtRchPaidAmt") as TextBox).Text;**
DSCallHistory.InsertParameters["RchAppID"].DefaultValue = DateTime.Parse(Convert.ToString(DateTime.Now)).ToString("dd MMM yyyy HH:MM");// strRchAppID;
DSCallHistory.InsertParameters["RchCallDate"].DefaultValue = strRchCallDate;
DSCallHistory.InsertParameters["RchComments"].DefaultValue = strRchComments;
DSCallHistory.InsertParameters["RchAttemptCall"].DefaultValue = strRchAttemptCall;
DSCallHistory.InsertParameters["RchReceivedParty"].DefaultValue = strRchReceivedParty;
DSCallHistory.InsertParameters["RchPrmTaken"].DefaultValue = strRchPrmTaken;
DSCallHistory.InsertParameters["RchCNPrm"].DefaultValue = strRchCNPrm;
DSCallHistory.InsertParameters["RchNxtPrmDate"].DefaultValue = strRchNxtPrmDate;
**if (strRchPaidAmt !=null)
{
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt);
}
else
{
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue ="0";
}**
DSCallHistory.Insert();
}
}
what should I do. Pls suggest me with best solution.
Thanks
Nur
Additional Information
<asp:SqlDataSource ID="DSCallHistory" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:OptimaWebCustomerQueryCon %>"
DeleteCommand="DELETE FROM [TblRecCallHistory] WHERE [RchID] = #RchID"
InsertCommand="INSERT INTO [TblRecCallHistory] ([RchAppID], [RchCallDate], [RchComments], [RchAttemptCall], [RchReceivedParty], [RchPrmTaken], [RchCNPrm], [RchNxtPrmDate], [RchPaidAmt]) VALUES (#RchAppID, #RchCallDate, #RchComments, #RchAttemptCall, #RchReceivedParty, #RchPrmTaken, #RchCNPrm, #RchNxtPrmDate, #RchPaidAmt)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [RchID], [RchAppID], [RchCallDate], [RchComments], [RchAttemptCall], [RchReceivedParty], [RchPrmTaken], [RchCNPrm],
[RchNxtPrmDate]=(case when [RchNxtPrmDate] = '01Jan1900' then NULL else [RchNxtPrmDate] end),
[RchPaidAmt] FROM [TblRecCallHistory] WHERE ([RchAppID] = #RchAppID) ORDER BY [RchID]"
UpdateCommand="UPDATE [TblRecCallHistory] SET [RchAppID] = #RchAppID, [RchCallDate] = #RchCallDate, [RchComments] = #RchComments, [RchAttemptCall] = #RchAttemptCall, [RchReceivedParty] = #RchReceivedParty, [RchPrmTaken] = #RchPrmTaken, [RchCNPrm] = #RchCNPrm, [RchNxtPrmDate] = #RchNxtPrmDate, [RchPaidAmt] = #RchPaidAmt WHERE [RchID] = #RchID">
<DeleteParameters>
<asp:Parameter Name="RchID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RchAppID" Type="Int32" />
<asp:Parameter Name="RchCallDate" Type="DateTime" />
<asp:Parameter Name="RchComments" Type="String" />
<asp:Parameter Name="RchAttemptCall" Type="Int32" />
<asp:Parameter Name="RchReceivedParty" Type="String" />
<asp:Parameter Name="RchPrmTaken" Type="Int32" />
<asp:Parameter Name="RchCNPrm" Type="Int32" />
<asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
<asp:Parameter Name="RchPaidAmt" Type="Decimal" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GVRecList" Name="RchAppID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="RchAppID" Type="Int32" />
<asp:Parameter Name="RchCallDate" Type="DateTime" />
<asp:Parameter Name="RchComments" Type="String" />
<asp:Parameter Name="RchAttemptCall" Type="Int32" />
<asp:Parameter Name="RchReceivedParty" Type="String" />
<asp:Parameter Name="RchPrmTaken" Type="Int32" />
<asp:Parameter Name="RchCNPrm" Type="Int32" />
<asp:Parameter Name="RchNxtPrmDate" Type="DateTime" />
<asp:Parameter Name="RchPaidAmt" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue ="0";
should be:
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue =0m;
Don't convert your decimal value before assigning it to DefaultValue - DefaultValue expects a string i.e.
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = strRchPaidAmt;
Change the following line of code
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt);
to be :
DSCallHistory.InsertParameters["RchPaidAmt"].DefaultValue = Convert.ToDecimal(strRchPaidAmt).ToString();
The problem is you are trying to set a decimal into a string object.
EDIT: Jame's solution is probably more appropriate.

Adding value to parameter in C# (asp.net) to be saved in SQL Server

I am quite new to ASP.NET and I am making my first application for my school project and I have one problem.
I have my database for adding files and pictures. I used a SqlDataSource and DataList, so I generate insert, update and delete automatically. In code-behind C#, I wrote code for adding images directly to database and file with path that goes to database, but I don't know how to add value (path) to parameter so it could all be saved together. What command should I use?
Maybe it is stupid question, but I don't have anyone to ask. Sorry If my code is a little bit funny looking here in this windowenter code here
Here is my C#
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
FileUpload kontrola = (FileUpload)FormView1.FindControl("FileUpload2");
if (kontrola.PostedFile != null && kontrola.PostedFile.FileName != "")
{
BinaryReader reader = new BinaryReader(kontrola.PostedFile.InputStream);
myImage = reader.ReadBytes(kontrola.PostedFile.ContentLength);
}
System.Data.SqlClient.SqlParameter uploadData =
new System.Data.SqlClient.SqlParameter("#image",System.Data.SqlDbType.Image);
uploadData.Value = myImage;
e.Command.Parameters.Add(uploadData);
FileUpload kontrola2 = (FileUpload)FormView1.FindControl("FileUpload1");
//Get Filename from fileupload control
string filename = Path.GetFileName(kontrola2.PostedFile.FileName);
//Save images into Images folder
kontrola2.SaveAs(Server.MapPath("~/files/" + kontrola2.FileName));
string valp = "files/" + kontrola2.FileName; // I am not sure if this is right
//e.Command.Parameters.Add["#data_file"].Value = valp; // this is not right, but this part I don't know
}
and this is my markup in aspx.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:repository_dbConnectionString %>"
SelectCommand="SELECT * FROM [data]"
DeleteCommand="DELETE FROM [data] WHERE [id] = #id"
InsertCommand="INSERT INTO [data] ([data_set_name], [abstract], [source], [multivariate], [unvariate], [sequentional], [time_series], [text], [domain_theory], [clasification], [regression], [clustering], [casual_discovery], [categorical], [integer], [real], [life_sciences], [physical_sciences], [cs_engineering], [social_sciences], [business], [game], [other], [matrix], [non_matrix], [yes], [no], [num_istances], [num_attributes], [relevant_info], [attribute_info], [relevant_papers], [citation_request], [data_file], [image], [date], [approval]) VALUES (#data_set_name, #abstract, #source, #multivariate, #unvariate, #sequentional, #time_series, #text, #domain_theory, #clasification, #regression, #clustering, #casual_discovery, #categorical, #integer, #real, #life_sciences, #physical_sciences, #cs_engineering, #social_sciences, #business, #game, #other, #matrix, #non_matrix, #yes, #no, #num_istances, #num_attributes, #relevant_info, #attribute_info, #relevant_papers, #citation_request, #data_file, #image, GetDate(), #approval)"
UpdateCommand...
oninserting="SqlDataSource1_Inserting">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="data_set_name" Type="String" />
<asp:Parameter Name="abstract" Type="String" />
<asp:Parameter Name="source" Type="String" />
<asp:Parameter Name="multivariate" Type="Boolean" />
<asp:Parameter Name="unvariate" Type="Boolean" />
<asp:Parameter Name="sequentional" Type="Boolean" />
<asp:Parameter Name="time_series" Type="Boolean" />
<asp:Parameter Name="text" Type="Boolean" />
<asp:Parameter Name="domain_theory" Type="Boolean" />
<asp:Parameter Name="clasification" Type="Boolean" />
<asp:Parameter Name="regression" Type="Boolean" />
<asp:Parameter Name="clustering" Type="Boolean" />
<asp:Parameter Name="casual_discovery" Type="Boolean" />
<asp:Parameter Name="categorical" Type="Boolean" />
<asp:Parameter Name="integer" Type="Boolean" />
<asp:Parameter Name="real" Type="Boolean" />
<asp:Parameter Name="life_sciences" Type="Boolean" />
<asp:Parameter Name="physical_sciences" Type="Boolean" />
<asp:Parameter Name="cs_engineering" Type="Boolean" />
<asp:Parameter Name="social_sciences" Type="Boolean" />
<asp:Parameter Name="business" Type="Boolean" />
<asp:Parameter Name="game" Type="Boolean" />
<asp:Parameter Name="other" Type="Boolean" />
<asp:Parameter Name="matrix" Type="Boolean" />
<asp:Parameter Name="non_matrix" Type="Boolean" />
<asp:Parameter Name="yes" Type="Boolean" />
<asp:Parameter Name="no" Type="Boolean" />
<asp:Parameter Name="num_istances" Type="Int32" />
<asp:Parameter Name="num_attributes" Type="Int32" />
<asp:Parameter Name="relevant_info" Type="String" />
<asp:Parameter Name="attribute_info" Type="String" />
<asp:Parameter Name="relevant_papers" Type="String" />
<asp:Parameter Name="citation_request" Type="String" />
<asp:Parameter Name="data_file" Type="String" />
<asp:Parameter DbType="Date" Name="date" />
<asp:Parameter Name="approval" Type="Boolean" />
</InsertParameters>
You've specified the Insert parameters in the SqlDataSource, so they'll already exist in the Parameters collection. You only need to call:
e.Command.Parameters["#data_file"].Value = ....
you can use in front-End aspx put edit text and FileUpload
after that in the back-End C# use same this
var conn = ConfigurationManager.ConnectionStrings["YesserDB"].ConnectionString;
using (var connection = new SqlConnection(conn))
{
SqlCommand cmd = new SqlCommand("INSERT INTO testOne (DocNo,DocSysNo,DocTypeID,DocDate,DocDateHj,DocSubjectID,DocDestinaionID,DocSoureceID,DocConfidentionyID,DocPriorityID,DocRemarks,DocAttributes) VALUES (#DocNo,#DocSysNo,#DocTypeID,#DocDate,#DocDateHj,#DocSubjectID,#DocDestinaionID,#DocSoureceID,#DocConfidentionyID,#DocPriorityID,#DocRemarks,#DocAttributes)", connection);
cmd.Parameters.AddWithValue("#DocNo", DocNo );
cmd.Parameters.AddWithValue("#DocSysNo", DocSysNo );
cmd.Parameters.AddWithValue("#DocTypeID", DocTypeID );
cmd.Parameters.AddWithValue("#DocDate", DocDate);
cmd.Parameters.AddWithValue("#DocDateHj", DocDateHj);
cmd.Parameters.AddWithValue("#DocSubjectID", DocSubjectID );
cmd.Parameters.AddWithValue("#DocDestinaionID",DocDestinaionID );
cmd.Parameters.AddWithValue("#DocSoureceID",DocSoureceID );
cmd.Parameters.AddWithValue("#DocConfidentionyID", DocConfidentionyID);
cmd.Parameters.AddWithValue("#DocPriorityID", DocPriorityID);
cmd.Parameters.AddWithValue("#DocRemarks", DocRemarks);
cmd.Parameters.AddWithValue("#DocAttributes", DocAttributes);
//cmd.Parameters.AddWithValue("#AttachFile", FileUpload1.TemplateControl);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

ASP.net, SQL database, Insert, TextBoxes

I am currently working in Visual Basic 2010 with a webform. I created an SQL database inside of Visual Basic and I'm trying to make the insert command move values from the textboxes into the database.
So my question is: how do I get the values from the textboxes (i.e:NameTextBox, AddressTextBox..) and associate them with the parameters (#Name, #Address1)?
The database works, I tested it by inputing values through the code.
Here is the relevant code:
<script runat="server">
' InsertShipper
Private Sub InsertShipper (ByVal Source As Object, ByVal e As EventArgs)
SqlDataSource1.Insert()
End Sub
</script>
<asp:Button ID="OrderButton" runat="server" onclick="InsertShipper" Text="Order" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:OrderListConnectionString %>"
DeleteCommand="DELETE FROM [ORDER] WHERE [OID] = #OID"
InsertCommand="INSERT INTO [ORDER] ([Name], [Address1], [Address2], [City], [State], [Zip], [Phone], [Email], [Subtotal], [Shipping]) VALUES ( #Name, #Address1, #Address2, #City, #State, #Zip, #Phone, #Email, #Subtotal, #Shipping)"
SelectCommand="SELECT * FROM [ORDER]"
UpdateCommand="UPDATE [ORDER] SET [Name] = #Name, [Address1] = #Address1, [Address2] = #Address2, [City] = #City, [State] = #State, [Zip] = #Zip, [Phone] = #Phone, [Email] = #Email, [Subtotal] = #Subtotal, [Shipping] = #Shipping WHERE [OID] = #OID">
<DeleteParameters>
<asp:Parameter Name="OID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter name="Name" Type="String" />
<asp:Parameter name="Address1" Type="String" />
<asp:Parameter Name="Address2" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="Zip" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Subtotal" Type="String" />
<asp:Parameter Name="Shipping" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Address1" Type="String" />
<asp:Parameter Name="Address2" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="Zip" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Subtotal" Type="String" />
<asp:Parameter Name="Shipping" Type="String" />
<asp:Parameter Name="OID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
Try setting the parameters' ControlID and PropertyName as such:
<asp:ControlParameter Name="Title"
ControlID="txtFoo"
PropertyName="Text"/>
Refer to http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx
Your parameters' Name property are missing the "#" character. You need to add this or it sees it as a completely different parameter.

No value given for one or more required parameters. showing error

<asp:AccessDataSource ID="productsubtype" Runat="server" DataFile="~/access_db/db_tables.mdb"
SelectCommand="SELECT [type], [id],[subtype] FROM [prod_subtype]"
UpdateCommand="UPDATE [prod_subtype] SET [subtype]=#subtype WHERE [id]=#id"
DeleteCommand="DELETE FROM [prod_subtype] WHERE [id]=#id"
FilterExpression="type='{0}'">
<UpdateParameters>
<asp:Parameter Name="subtype" Type="string" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="id" Type="string" />
</DeleteParameters>
<FilterParameters>
<asp:ControlParameter Name="type" DefaultValue="-1"
Type="String" ControlID="gdproducttype"
PropertyName="SelectedValue"></asp:ControlParameter>
</FilterParameters>
</asp:AccessDataSource>
When i press delete button in gridview i am getting error
Try changing your UpdateParameters to the following:
<UpdateParameters>
<asp:Parameter Name="id" Type="string" />
<asp:Parameter Name="subtype" Type="string" />
</UpdateParameters>

Resources