|
i have a dropdownlist i bind it such like that it has different valuefield and different textfield. i want that i select textfield from dropdown and the value correspond that valuefield will insert in the database i write a code for it, it show datatype error.Failed to convert parameter value from string to a byte
<asp:DropDownList ID="ddlCType" runat="server"
DataSourceID="SqlDataSource1" DataTextField="CouponName"
DataValueField="CouponTypeID"
style="top: 309px; left: 389px; position: absolute; height: 11px; width: 97px; z-index: 1"
AutoPostBack="True" ontextchanged="DropDownList1_TextChanged">
</asp:DropDownList>
try
{
ErrorMessage.Text = "";
cnx.Open();
SqlCommand insertCmd = new SqlCommand("insert into CouponTransaction(CouponTypeID)values(@Id)", cnx);
insertCmd.Parameters.Add("@Id", SqlDbType.TinyInt);
insertCmd.Parameters["@Id"].Value = ddlCType.Text;insertCmd.ExecuteNonQuery();
ErrorMessage.Text = "Records inserted successfully";
cnx.Close();
}
|
|
|
|
|
haleemasher wrote: insertCmd.Parameters["@Id"].Value = ddlCType.Text;
You should use ddlCType.SelectedValue property for dropdownlist's selected item's value.
Be an Eagle, Sky is Yours.
|
|
|
|
|
Same error may i change this code also
insertCmd.Parameters.Add("@Id", SqlDbType.TinyInt);
|
|
|
|
|
Hi,
insertCmd.Parameters["@Id"].Value = ddlCType.Text;insertCmd.ExecuteNonQuery();
replace the above code with
insertCmd.Parameters["@Id"].Value = int.Parse(ddlCType.SelectedValue);insertCmd.ExecuteNonQuery();
|
|
|
|
|
haleemasher wrote: insertCmd.Parameters["@Id"].Value = ddlCType.Text
Use
insertCmd.Parameters["@Id"].Value = Convert.ToByte(ddlCType.SelectedValue);
Viral
|
|
|
|
|
it show another error Input sting was not in correct format
|
|
|
|
|
sorry my mistake
Use
insertCmd.Parameters["@Id"].Value = Convert.Int32(ddlCType.SelectedValue);
here you can use Int32 or Int16 depends on your requirement.
Hope this help
Viral
|
|
|
|
|
Hey! I need to display confirmation message in asp.net. I need to do something like this. Once user click Ok button some code execute and then return the confirmation message. According to the use response other code execute.Basically it is if/else statement. please help me how can i do it
Dushan Perera
|
|
|
|
|
|
- Add "OnClick" attribute on button and call javascript method.
- In this method write the Javascript confirmation message and on the basis on user response return true or false.
Note: Don't forget to return True or False
|
|
|
|
|
Basically i need common method to display the message. This class or page can use in the entire project
Dushan Perera
|
|
|
|
|
You can use Comman Floating DIV with Message and Button. This will make the things very easy. On any button click show the DIV and take the event from the DIV Button.
You can also look into JavaScript Confirm Box .
|
|
|
|
|
Dear friends,
i wrote a asp.net webservice using vs 2008 .net framework 3.5. this service runs over https.
it gets the parameters from the client and sends this to another application and then the answer from that application back to the client.
It works sometimes fine, bud sometimes im getting this exception:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Net.WebException: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF
at System.Net.HttpWebRequest.GetResponse()
at WebService2.Service1.HttpSOAPRequest(String xmlfile, String proxy) in C:\Documents and Settings\BB\My Documents\Visual Studio 2008\Projects\WebService2\WebService2\Service1.asmx.cs:line 44
at WebService2.Service1.CardWithPerson(String persId, String projectId, String username, String pw) in C:\Documents and Settings\BB\My Documents\Visual Studio 2008\Projects\WebService2\WebService2\Service1.asmx.cs:line 82
--- End of inner exception stack trace ---
Here is some code of the webservice:
[WebMethod]
public String CardWithPerson(string persId, string projectId, string username, string pw)
{
xmlfile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\">"
+"<soap:Body>"
+"<PS_CardsWithPersonReq xmlns=\"http://tempuri.org\">"
+"<WebAuthenticate>"
+" <WebUser>"+username+"</WebUser>"
+" <WebPass>"+pw+"</WebPass>"
+" <WebIp>"+Context.Request.UserHostAddress+"</WebIp>"
+" <WebMd>0123456789ABCDEF0123</WebMd>"
+" </WebAuthenticate>"
+"<PersNr>"+persId+"</PersNr>"
+"<Lang>E</Lang>"
+"<ProjCode>"+projectId+"</ProjCode>"
+"</PS_CardsWithPersonReq>"
+"</soap:Body>"
+"</soap:Envelope>";
r = HttpSOAPRequest(xmlfile, null);
result = r.ReadToEnd();
return result;
}
StreamReader HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfile);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://211.144.244.244:7871");
if (proxy != null) req.Proxy = new WebProxy(proxy, true);
req.Headers.Add("SOAPAction", "\"\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader strmReader = new StreamReader(stm);
return strmReader;
}
Here the code of the client side:
protected void Button1_Click(object sender, EventArgs e)
{
nl.test.testsoap.Service1 serv = new WebApplication1.nl.test.testsoap.Service1();
Response.Write(serv.CardWithPerson(textPersId.Text, txtProCode.Text, username, pw));
Response.End();
}
Can anyone help me with this issue?
Thanks
|
|
|
|
|
Just guessing, but the problem might occur when some of your variables (username, pwd, persID, projectId, ....) have invalid chars, like xml schema chars.
Seems your webservice is accessing other webservice, right? If you're using Visual Studio, you can just reference the other webservice (Right click on project -> Add Web Reference). VS will automatically create a new class encapsulating the webservice, so you just call for WebServiceClass.PS_CardsWithPersonReq method with the parameters. You might need WS Secutity to authenticate.
Regards,
Leonardo Muzzi
|
|
|
|
|
Hi,
Can you please highlight the line numbers indicated in the error message or can you paste the code with the line numbers.
Gayani
|
|
|
|
|
Hi Gayani Devapriya,
Thanks for your response.
This is the line:
WebResponse resp = req.GetResponse();
You can see it In the methode: StreamReader HttpSOAPRequest(String xmlfile, string proxy)
|
|
|
|
|
Hi,
The problem is solved by adding
req.KeepAlive = false;
ofter creating the request
|
|
|
|
|
I used the following code to redirect from current page is this correct?
I don't want to write a javascript function for this one line,
instead of i wish to redirect using this method.can i do?
imgbtnUserIcon.Attributes.Add("onclick", "javascript:window.location.href('memberactiveprofile.aspx')");
|
|
|
|
|
Response.Redirect("aaa.aspx")
|
|
|
|
|
amarnath n.n wrote: Subject:Please reply me
This should not be the subject. It should be your query.
amarnath n.n wrote: I don't want to write a javascript function for this one line,
instead of i wish to redirect using this method.can i do?
Is it server side control ? if yes, then OnClick Event use Response.Redirect() ; to navigate .
|
|
|
|
|
First, before posting again please read How to get an answer to your question at the top of this forum.
If you want to do it client-side then
mgbtnUserIcon.Attributes.Add("onclick", "javascript:window.location.href='memberactiveprofile.aspx'");
window.location.href is a property, not a method;
only two letters away from being an asset
|
|
|
|
|
Hi Guys,
I am working on a project and want to add Windows Media Player control on a webpage.
But I am not able to find windows media control on my tool box.
I am using visual studio2008.
Please help me with sample code.
Thanks
|
|
|
|
|
Here [^]is an example for this.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
<%@ page language="vb" runat="server" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat=server>
Sub Page_Load()
If (Not IsPostBack) then
LoadData()
End If
End Sub
Sub LoadData()
dim OurConnection as OleDbConnection
dim OurCommand as OleDbCommand
dim OurDataAdapter as OleDbDataAdapter
dim OurDataSet as New DataSet()
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurConnection.Open()
OurCommand = New OleDbCommand("Select FirstName,LastName from Employees",OurConnection)
OurDataAdapter = New OleDbDataAdapter(OurCommand)
OurDataAdapter.Fill(OurDataSet, "Employees")
OurDataGrid.DataSource=OurDataSet.Tables("Employees")
UpdateEmployeeID.DataSource=OurDataSet.Tables("Employees")
DeleteEmployeeID.DataSource=OurDataSet.Tables("Employees")
DataBind()
End Sub
Sub UpdateSetup(sender As Object, e As System.EventArgs)
UpdateSelect.Visible="False"
UpdateTextBoxes.Visible="True"
dim SelectedID as String = UpdateEmployeeID.SelectedItem.Value
UpdateButton.CommandArgument = SelectedID
dim OurConnection as OleDbConnection
OurConnection = New OleDbConnection("Server=server;uid=newriders;pwd=password;database=Northwind")
OurConnection.Open()
dim OurCommand as OleDbCommand
dim OurDataReader2 as OleDbDataReader
OurCommand = New OleDbCommand("Select FirstName, LastName From Employees Where EmployeeID = " + SelectedID ,OurConnection)
OurDataReader2 = OurCommand.ExecuteReader()
OurDataReader2.Read()
UpdateFirstName.Visible="True"
UpdateLastName.Visible="True"
UpdateFirstName.Text = OurDataReader2("FirstName")
UpdateLastName.Text = OurDataReader2("LastName")
OurConnection.Close()
OurDataReader2.Close()
LoadData()
End Sub
Sub UpdateReset(sender As Object, e As System.EventArgs)
UpdateSelect.Visible="True"
UpdateTextBoxes.Visible="False"
LoadData()
End Sub
Sub InsertCommand(sender As Object, e As System.EventArgs)
dim OurConnection as OleDbConnection
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
dim OurCommand as OleDbCommand
OurCommand = New OleDbCommand("Insert Into Employees (FirstName, LastName) Values (@FirstName, @LastName)" ,OurConnection)
OurCommand.Parameters.Add("@FirstName", oledbType.Varchar, 10).Value = InsertFirstName.Text
OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value = InsertLastName.Text
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
Sub UpdateCommand(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
dim OurConnection as OleDbConnection
dim OurCommand as OleDbCommand
dim EmployeeID as String = e.CommandArgument
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurCommand = New OleDbCommand("Update Employees Set Firstname = @FirstName,LastName = @LastName Where EmployeeID = " +EmployeeID, OurConnection)
OurCommand.Parameters.Add("@FirstName", oledbType.Varchar, 10).Value =UpdateFirstName.Text
OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value =UpdateLastName.Text
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
Sub DeleteCommand(sender As Object, e As System.EventArgs)
dim OurConnection as oledbConnection
dim SelectedID as String = DeleteEmployeeID.SelectedItem.Value
dim OurCommand as oledbCommand
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurCommand = New oledbCommand("Delete Employees Where EmployeeID = " + SelectedID, OurConnection)
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
</script>
<html>
<head>
<title>ADO oledbCommand -Insert,Update,Delete</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form runat="server">
<table border="0" cellpadding="0" cellspacing="20">
<tr><td>
<ASP:DataGrid
id="OurDataGrid"
EnableViewState="false"
BorderWidth="1"
BorderColor="#000000"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
HeaderStyle-BackColor="#AAAAAA"
ItemStyle-BackColor="#EEEEEE"
runat="server" />
</td><td>
<h4>Insert</h4>
First Name: <asp:TextBox id="InsertFirstName" runat="server" /><br>
Last Name: <asp:TextBox id="InsertLastName" runat="server" />
<asp:button runat="server" OnClick="InsertCommand" text="Submit" /><br><br>
<hr style="height:1px">
<h4>Update</h4>
<asp:Panel id="UpdateSelect" runat="server" >
EmployeeID:
<asp:DropDownList
id="UpdateEmployeeID"
DataTextField="EmployeeID"
DataValueField="EmployeeID"
runat="server" />
<asp:button runat="server" text="Select" OnClick="UpdateSetup" />
</asp:Panel>
<asp:Panel id="UpdateTextBoxes" Visible="false" runat="server" >
First Name: <asp:TextBox id="UpdateFirstName" runat="server" />
<asp:button
id="UpdateButton"
onCommand="UpdateCommand"
runat="server"
text="Update" /><br>
Last Name: <asp:TextBox id="UpdateLastName" runat="server" />
<asp:button id="CancelUpdateButton" runat="server" onClick="UpdateReset" text="Select
Other" />
</asp:Panel><br>
<hr style="height:1px">
<h4>Delete</h4>
EmployeeID:
<asp:DropDownList
id="DeleteEmployeeID"
DataTextField="EmployeeID"
DataValueField="EmployeeID"
runat="server" />
<asp:button runat="server" text="Delete" onClick="DeleteCommand" />
</td></tr>
</table>
</form>
</body>
</html>
returns d ff errors
Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.
Source Error:
Line 70: OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value = InsertLastName.Text
Line 71: OurConnection.Open()
Line 72: OurCommand.ExecuteNonQuery()
Line 73: OurConnection.Close()
Line 74:
Source File: c:\inetpub\wwwroot\sat.aspx Line: 72
Stack Trace:
what should i do pls
thanks
abiola
|
|
|
|
|
Hello all,
I am trying to find a way of telling in a .net page load method whether or not it was called by a browser extension.
The reason it came up is that I recently installed the skype extension for Firefox and found that a page I was developing was suddenly reloading every 2 seconds. The main code for the page is called within a "If Not Page.IsPostBack Then" statement in the page load, but the reload from the extension was not being caught by this. After a lot of searching it turned out to be the skype extension.
It is no problem for me to uninstall the extension, but I know there are a few of our clients that use skype and the skype add-on. It would be a big inconvenience to them if they would have to disable and re-enable the add-on just to view certain pages in our app.
Is there anyway of telling if an extension calls a reload instead of ordinary page events?
thank you ,
Aaran
|
|
|
|