SQL og ASP.NET
<script runat="server">void Page_Load(object Sender ,EventArgs E)
{
}
void City(object Sender ,EventArgs E)
{
string strConnection = "user id=sa;password=;";
strConnection += "initial catalog=naftech;data source=(local);";
strConnection += "Connect Timeout=30";
//data_src.Text = strConnection;
SqlConnection objConnection = new SqlConnection(strConnection);
try
{
objConnection.Open();
lblBeskedDone.Text="Forbindelse til DB er etableret";
string sqlstring = "select City from byTabel where postTabel. ";
sqlstring += tbPost.Text;
SqlCommand myCommand = new SqlCommand(sqlstring, objConnection);
myCommand.ExecuteNonQuery();
objConnection.Close();
}
catch (Exception e)
{
lblBeskedFejl.Text="Etablering af forbindelse fejlet!";
}
}
//-------------------------------------------------------------------------------------------
void BehandlData(object Sender ,EventArgs E)
{
string strConnection = "user id=sa;password=;";
strConnection += "initial catalog=naftech;data source=(local);";
strConnection += "Connect Timeout=30";
//data_src.Text = strConnection;
SqlConnection objConnection = new SqlConnection(strConnection);
try
{
objConnection.Open();
lblBeskedDone.Text="Forbindelse til DB er etableret";
string insertCmd = "insert into kontaktTabel (Navn, Adresse, Postnr, Ciy, Email, Kommentar) values ";
insertCmd += tbNavn.Text + "', '";
insertCmd += tbAdr.Text + "', '";
insertCmd += tbPost.Text + "', '";
insertCmd += lblBy.Text + "', '";
insertCmd += tbEmail.Text + "', '";
insertCmd += tbBesked.Text + "')";
// lblBesked4.Text = insertCmd;
SqlCommand myCommand = new SqlCommand(insertCmd, objConnection);
myCommand.ExecuteNonQuery();
lblBeskedDone.Text="fejlen";
objConnection.Close();
lblBeskedFejl.Text="Forbindelse er lukket";
}
catch (Exception e)
{
lblBeskedFejl.Text="Etablering af forbindelse fejlet!";
}
}
//---------------------------------------------------------------------------------------------
void RydFelter(object Sender ,EventArgs E)
{
tbNavn.Text="";
tbAdr.Text="";
tbPost.Text="";
lblBy.Text="";
tbEmail.Text="";
tbBesked.Text="";
lblBeskedFejl.Text="";
lblBeskedDone.Text="";
}
</script>
Af en eller anden grund, så smider den ikke noget ind i min database når jeg køre koden... Nogen der har nogle ider?
